Halloween Sale 15% off Ends in See the plans
PHP

Site Identity REST Endpoint for Apps and Headless Sites

Adds a public /wp-json/site/v1/identity endpoint with the site name, tagline, logo, site icon, language and home URL, so headless front ends and apps can brand themselves from WordPress.

Don’t have WPIDE yet? Install it on your site

Code

add_action( 'rest_api_init', function () {
    register_rest_route( 'site/v1', '/identity', array(
        'methods'             => WP_REST_Server::READABLE,
        'permission_callback' => '__return_true',
        'callback'            => function () {
            $logo_id  = (int) get_theme_mod( 'custom_logo' );
            $response = new WP_REST_Response( array(
                'name'        => get_bloginfo( 'name' ),
                'description' => get_bloginfo( 'description' ),
                'url'         => home_url( '/' ),
                'language'    => get_bloginfo( 'language' ),
                'logo'        => $logo_id ? wp_get_attachment_image_url( $logo_id, 'full' ) : null,
                'icon'        => get_site_icon_url( 512 ) ? get_site_icon_url( 512 ) : null,
                'timezone'    => wp_timezone_string(),
            ) );
            $response->header( 'Cache-Control', 'public, max-age=3600' );
            return $response;
        },
    ) );
} );

Notes

Only public information is returned; the response can be cached by browsers for an hour.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.