Shortcodes not working in schema
-
We have shortcodes in our post titles. Here’s an example:
Product #3682: $[current_price]
To apply them to the rendered output, we use these lines in our child theme’s functions.php file:
add_filter('the_title', 'do_shortcode'); add_filter('single_post_title', 'do_shortcode'); add_filter('aioseo_title', 'do_shortcode'); add_filter('aioseo_description', 'do_shortcode');
That solution works well in most cases, but it looks like the raw shortcode still appears in the AIOSEO schema:
<script type="application/ld+json" class="aioseo-schema"> ...,"name":"Product #3682: $[current_price]","... </script>
The cause of this issue appears to be line 138 in
\app\Common\Schema\Graphs
:case '%postname%': $breadcrumb = [ 'name' => $post->post_title, 'description' => aioseo()->meta->description->getDescription( $post ), 'url' => $url[0], 'type' => $this->getPostGraph() ]; break;
The value of $post->post_title isn’t being filtered, so instead it outputs the raw, unapplied shortcode.
Interestingly, looking through the rest of that file, the post title related code seems to be pretty inconsistent in general. At a glance, I see three different methods being used to retrieve the post title:
Method 1: $post->post_title Method 2: aioseo()->meta->title->getTitle( $post ) Method 3: aioseo()->meta->title->prepareTitle( aioseo()->options->searchAppearance->archives->author->title )
Method 2 seems to fix the breadcrumb schema shortcode issue mentioned above, so it would be nice if you could modify the relevant code to look like this:
case '%postname%': $breadcrumb = [ 'name' => aioseo()->meta->title->getTitle( $post ), 'description' => aioseo()->meta->description->getDescription( $post ), 'url' => $url[0], 'type' => $this->getPostGraph() ]; break;
- The topic ‘Shortcodes not working in schema’ is closed to new replies.