URL / Rewrite Filter

How to get WordPress REST API to use SITE URL instead of HOME URL in Guttenberg editor

If you have a different SITE URL and HOME URL ( WordPress Address ), then, WordPress will use HOME URL for WordPress API. Here is an example: If your SITE URL is but your HOME URL or WordPress Address ( URL ) is, Then, your WordPress API URL will be But you may want to change it to

Here is the snippet code is given below, which uses ‘rest_url‘ filter to replace the HOME URL in REST API URL to SITE URL.

// change WordPress API URL to HOME URL
add_filter('rest_url', 'wptips_home_url_as_api_url');
function wptips_home_url_as_api_url($url) {
    $url = str_replace(home_url(),site_url() , $url);
    return $url;

By Murali Kumar

I am a Full Stack Web Developer with over 12 years of experience and I love WordPress & Woocommerce.

If you need help of a WordPress developer, Get in touch now!.

Leave a Reply

Your email address will not be published. Required fields are marked *