Test Structured Data From the Admin Bar
Adds a toolbar menu for editors on the front end that opens the current page in Google's Rich Results Test or the Schema.org validator.
Opens WPIDE on
Code
add_action( 'admin_bar_menu', function ( $bar ) {
if ( is_admin() || ! current_user_can( 'edit_posts' ) ) {
return;
}
$url = home_url( add_query_arg( array() ) );
$bar->add_node( array( 'id' => 'wpide-schema-test', 'title' => 'Test schema', 'href' => false ) );
$bar->add_node( array( 'id' => 'wpide-rich-results', 'parent' => 'wpide-schema-test', 'title' => 'Google Rich Results Test', 'href' => 'https://search.google.com/test/rich-results?url=' . rawurlencode( $url ), 'meta' => array( 'target' => '_blank', 'rel' => 'noopener' ) ) );
$bar->add_node( array( 'id' => 'wpide-schema-validator', 'parent' => 'wpide-schema-test', 'title' => 'Schema.org Validator', 'href' => 'https://validator.schema.org/#url=' . rawurlencode( $url ), 'meta' => array( 'target' => '_blank', 'rel' => 'noopener' ) ) );
}, 90 );
Notes
The page must be publicly reachable for the testing tools to fetch it.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.