Using WordPress shortcode in a title

青春壹個敷衍的年華 提交于 2020-04-10 04:25:35

问题


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?


回答1:


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/.




回答2:


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' );


来源:https://stackoverflow.com/questions/6845403/using-wordpress-shortcode-in-a-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!