conditional shortcodes – WordPress Development Stack Exchange


I want to use a shortcode ([ex]...[/ex]) within the title of a post in order to style the text in a certain way (<h1>part of <span class="ex">title</span></h1>).

Thanks to add_filter( 'the_title', 'do_shortcode' );, it works perfectly with the_title.

But now, single_post_title which I use for <title> contains the shortcode as plain text <title>part of [ex]title[/ex]</title>. With add_filter( 'single_post_title', 'do_shortcode' );, the title becomes <title>part of <span class="ex">title</span></title>.

Is there a way to make shortcodes conditional: if it’s resolved within the_title do this, within single_post_title do that?

Tom J Nowell 2 months 2023-04-06T11:24:39-05:00 0 Answers 0 views 0

Leave an answer