How to call Javascript function in PHP?

How do I call a plugin function inside a PHP template for WP sites?

  • I am using a pagination plugin in my WP site. As pagination works, it  must be laid inside an index.php file, else it will not show the output.  But i wish to call the same function in a template file. I have the php  code but when I call that function or add that php code in header or  so, it does not work for obvious reasons. Now, I thought to copy the same function and place it elsewhere working dynamically where changes in the parent files, say in pagination function, will affect that in other files instantly. Scenario (Pagination in the body of the website) Pages- 1,2,3,4,5...10 Placing/calling the exact thing in another place working the way hte parent function is working. Hope it makes sense. Let me know if I can achieve this. Note: This is something like copy link function in MS Excel or in spreadsheet where a change in one cell dynamically change the other where that function exists.

  • Answer:

    Just  a simple suggestion that instead of making multiple copies of same  function, why not create a Shortcode of that function and you can call  that function using do_shortcode. Creating shortcode // [bartag foo="foo-value"] function bartag_func( $atts ) { extract( shortcode_atts( array( 'foo' => 'something', 'bar' => 'something else', ), $atts ) ); return "foo = {$foo}"; } add_shortcode( 'bartag', 'bartag_func' ); To call the shortcode echo do_shortcode('[bartag foo="foo-value"]'); To know about shortcode follow the link: http://codex.wordpress.org/Shortcode_API

Rahul Balakrishna at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.