0

Normally I use this snippet to set the a custom logo inside my custom themes. I'm a noob with the theme settings API and settings API so I don't have at the moment a theme options page. I'm developing a vue.js based theme and I want to get all the data using axios. Is there a REST endpoin I can use to get the logo or I need to register a custom route like I'm doing for the menù and other themes resources?

<a class="navbar-brand ml-auto" href="<?php bloginfo('url'); ?>">
      <?php $logo = wp_get_attachment_image_src( get_theme_mod('custom_logo'), 'full' ); ?>
      <?php if( $logo ): ?>
        <img src="<?php //echo $logo[0]; ?>" width="auto" height="75">
      <?php endif; ?>
      </a>
0

1 Answer 1

0

Is there a REST endpoint I can use to get the logo

As far as I know, none that's specific to theme mods.

or I need to register a custom route like I'm doing for the menu and other themes resources?

I would not say yes or no, but it's easy to create custom endpoints and you'd also get the data (in the API response) in the format you prefer (string, object, array, etc.), so why not and you could have something simple like:

function my_theme_register_rest_routes() {
    // For retrieving all theme mods.
    // Sample request URL: http://example.com/wp-json/mytheme/v1/settings?_wpnonce=XXXXXXXXXX
    register_rest_route( 'mytheme/v1', '/settings', [
        'methods'  => 'GET',
        'callback' => function () {
            return get_theme_mods();
        },
        'permission_callback' => function () {
            return current_user_can( 'manage_options' );
        },
    ] );

    // For retrieving a specific theme mod.
    // Sample request URL: http://example.com/wp-json/mytheme/v1/settings/custom_logo?_wpnonce=XXXXXXXXXX
    register_rest_route( 'mytheme/v1', '/settings/(?P<name>[a-zA-Z0-9\-_]+)', [
        'methods'  => 'GET',
        'callback' => function ( $request ) {
            return get_theme_mod( $request->get_param( 'name' ) );
        },
        'permission_callback' => function () {
            return current_user_can( 'manage_options' );
        },
    ] );
}
add_action( 'rest_api_init', 'my_theme_register_rest_routes' );

But anyway, I thought this question might help you. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.