Skip to main content
FolksSpeakersPluginsThemesEventsSnippetsShippedCommunityResources
Login Join
Snippet · PHP

Add a Custom REST API Site Info Field

Shared by Yusuf mudagal · May 3, 2026 · @rest_api_init

4 views
Back to Snippets

Adds a small custom REST field to posts so front ends can read the site name without making a second settings request.

add_action( 'rest_api_init', 'wpfolks_register_post_site_name_field' );

function wpfolks_register_post_site_name_field() {
    register_rest_field( 'post', 'site_name', array(
        'get_callback' => static function () {
            return get_bloginfo( 'name' );
        },
        'schema' => array(
            'type' => 'string',
        ),
    ) );
}