Skip to content

Snippet: How to Change the HTML Schema Microdata

By default the Total theme adds the WebPage schema markup to the HTML tag as microdata (inline as opposed to JSON-LD). If you are using the Yoast SEO plugin you can of course change the default schema markup for your page via the plugin, however, you can also use a filter to modify the theme default theme schema markup.

For example if you want to create an FAQ page you will want your page to use the FAQPage schema markup. If you are using Yoast SEO you can always use the Yoast FAQ block, however, this block is very limited and perhaps you rather use the theme's Toggle element or even a custom card (adding FAQ via a post type). The following snippet shows how you may change the WebPage markup to FAQ on the FAQ page.

 * Change the HTML Schema Microdata.
 * @link
 * @param string $schema   The schema markup.
 * @param string $location The current theme location.
 * @return string $schema markup
add_filter( 'wpex_schema_markup', function( $schema, $location ) {
    if ( 'html' === $location && is_page( 'faq' ) ) {
        $schema = 'itemscope itemtype=""';
    return $schema;
}, 10, 2 );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top