Jump to content
Sign in to follow this  
ttc_mn

Using shortcodes with hooks

Recommended Posts

ttc_mn

In the functions.php file of platformbase added the following code: ` add_action('pagelines_before_brandnav','add_tedtimer'); function add_tedtimer () { echo do_shortcode ('[dtimer]'); } // [dtimer] is valid shortcode from a plugin that works fine in regular posts ` Result: The hook places only the text "[dtimer]" in the proper location before the brandnav (not the result of calling dtimer). Is it possible to use shortcodes with hooks? If so, what am I doing wrong? Thanks.

Share this post


Link to post
Share on other sites
Simon

` add_action('pagelines_header','my_example'); function my_example () { echo do_shortcode ('[show_hello]'); } function hello_function() { echo 'hello'; } add_shortcode('show_hello', 'hello_function' ); ` This works fine.

Share this post


Link to post
Share on other sites
ttc_mn

Thanks Simon - your example works fine. You defined the function "hello_function ()" and added the shortcode for "hello_function" in the same php file. I want to 'call' a shortcode that already exists in a separate plugin file (in the 'plugins' directory) that contains numerous shortcodes. Does this make sense?

Share this post


Link to post
Share on other sites
Simon

If the shortcode has previously been defined then it would not matter what file it is in.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×