Site logo

Archived topic

Change 'itemtype='http://schema.org/WebPage' Function

3 replies · Started by scott doel on November 1, 2017

Viewing posts 1–4 of 4

Hi is it possible to unhook the itemtype='http://schema.org/WebPage and replace it with the below?

<?php if ( is_page( array( 'about', 'about-us' ) ) ) { echo 'itemscope itemtype="http://schema.org/AboutPage"';
} elseif ( is_page( array( 'contact', 'contact-us' ) ) ) { echo 'itemscope itemtype="http://schema.org/ContactPage"';
} elseif ( is_search () ) { echo 'itemscope itemtype="http://schema.org/SearchResultsPage"';
} elseif ( is_front_page () ) {	echo 'itemscope itemtype="http://schema.org/WebPage"';
} elseif (is_single () ) { echo 'itemscope itemtype="http://schema.org/Article"';
} else { echo 'itemscope itemtype="http://schema.org/WebPage"'; // just in case we are at an unclassified page, perhaps the home page
} ?>

You could do this:

add_filter( 'generate_body_itemtype', 'tu_custom_body_itemtype' );
function tu_custom_body_itemtype( $type ) {
    if ( is_page( array( 'about', 'about-us' ) ) ) { 
        return 'AboutPage';
    } elseif ( is_page( array( 'contact', 'contact-us' ) ) ) { 
        return 'ContactPage';
    } elseif ( is_search() ) { 
        return 'SearchResultsPage';
    } elseif ( is_front_page() ) {
        return 'WebPage';
    } elseif (is_single() ) {
        return 'Article';
    } else {
        return 'WebPage';
    }
}

Sorry for the late response Tom, the snippet above worked perfectly thank you

You're welcome :)

This archived topic is closed to new replies.