# 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.

- Type: PHP
- Runs: Frontend only
- Category: [SEO](https://wpide.com/library/category/seo/)
- Tags: schema, admin-bar, testing
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/seo-rich-results-admin-bar/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Test Structured Data From the Admin Bar" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
