Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using WordPress shortcode in a title

I have some shortcodes which work fine inside a WordPress post or page. Is there anything I can add to functions.php to enable a shortcode to work inside a WordPress post title?

like image 928
Andrew Smart Avatar asked Jul 27 '11 13:07

Andrew Smart


2 Answers

You could try adding a filter to the title in the functions.php file such as:

add_filter( 'the_title', 'do_shortcode' );

Seems to work for me, however it may play havoc with your permalink's and I wouldn't recommend it.

In future WordPress related questions might be better directed at https://wordpress.stackexchange.com/.

like image 151
David Hancock Avatar answered Oct 01 '22 19:10

David Hancock


Add the following filter to functions.php as mentioned by David

add_filter( 'the_title', 'do_shortcode' );

However, this approach may not work if you are using the Yoast SEO plugin. For that, you need to add the following filter too:

add_filter( 'wpseo_title', 'do_shortcode' );
like image 31
heyitsritesh Avatar answered Oct 01 '22 20:10

heyitsritesh