• The current link metatag for my site looks like this:

    <link rel='https://api.w.org/' href='http://mysite.com/wp-json/' />

    However, I have my site inside a directory named “site” so it should read:

    <link rel='https://api.w.org/' href='http://mysite.com/site/wp-json/' />

    Is there a way I can fix this or must it wait for an update?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello Trishah,
    This link is created by wordpress and the url “http://mysite.com/wp-json/&#8221; is created by your site’s home url.
    Please see the home url of your site it should be “http://mysite.com/&#8221; or write the following code in your functions.php

    <?php
    echo get_home_url();
    ?>

    And you’ll see the home url of your site it must be “http://mysite.com/&#8221;, that’s why the link url is “http://mysite.com/wp-json/&#8221;.
    I would suggest that please don’t change it because this is the rest api response url created by wordpress, but if you want to change it then add the following code in your functions.php

    <?php
    add_filter( 'rest_url', 'your_function' );
    function your_function( $url ) {
     return 'http://mysite.com/site/wp-json/';
    }
    ?>

    And when you need to get the old url back then just remove the above code.

    Thread Starter trishahdee

    (@trishahdee)

    I see your point. My point is, because some of us put WordPress in it’s own directory, the home_url will be wrong for all of us… not just me.

    Wouldn’t it be better for the core to use <?php echo site_url(); ?> instead so the url points to the correct file not matter where WordPress is installed?

    If you want to change that url, you can change that either using site url or statically, by the filter “rest_url” as told earlier, or like below.

    <?php
        add_filter( 'rest_url', 'your_function' );
        function your_function( $url ) {
        return 'http://mysite.com/site/wp-json/';
        }
    ?>

    You can change the return url accordingly.

    Thread Starter trishahdee

    (@trishahdee)

    I think I posted this in the wrong category. How to I switch this to “Requests and Feedback”?

    Hi, @trishah.

    Wouldn’t it be better for the core to use <?php echo site_url(); ?> instead so the url points to the correct file not matter where WordPress is installed?

    You might want to have a look at Trac ticket #37020 (as I think it explains why this is the way it is).

    Thread Starter trishahdee

    (@trishahdee)

    From Trac ticket #37020:

    The REST API endpoints use home_url() by design for a few reasons:

    1. some endpoint data is publicly discoverable so the public facing url (aka home_url) is a better fit
    2. we use rewrites to route endpoint requests and guarantee being able to rewrite the site_url()

    1. If the file is not in that location and so is not “discoverable” there, it does not make sense to me that home-url is a better fit.
    2. Is beyond my technical ability to understand.

    I would be interested to know what percentage of WordPress installs are in their own directories to see how many this decision will effect.

    @trishah: What exactly do you see in your browser if you visit http://mysite.com/wp-json/ in it? (Replacing mysite with your real domain name, of course.)

    Thread Starter trishahdee

    (@trishahdee)

    I’ve replaced the site identifying information with filler:

    {"name":"Site Name","description":"Tagline","url":"http:\/\/mysite.com\/site","home":"http:\/\/mysite.com","namespaces":["oembed\/1.0"],"authentication":[],"routes":{"\/":{"namespace":"","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false,"default":"view"}}}],"_links":{"self":"http:\/\/mysite.com\/wp-json\/"}},"\/oembed\/1.0":{"namespace":"oembed\/1.0","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"namespace":{"required":false,"default":"oembed\/1.0"},"context":{"required":false,"default":"view"}}}],"_links":{"self":"http:\/\/mysite.com\/wp-json\/oembed\/1.0"}},"\/oembed\/1.0\/embed":{"namespace":"oembed\/1.0","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"url":{"required":true},"format":{"required":false,"default":"json"},"maxwidth":{"required":false,"default":600}}}],"_links":{"self":"http:\/\/mysite.com\/wp-json\/oembed\/1.0\/embed"}}},"_links":{"help":[{"href":"http:\/\/v2.wp-api.org\/"}]}}

    Is this what it is supposed to be?

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    That looks pretty much like what it looks like for my site, so all in all I’d say it’s working as designed.

    https://www.sterndata.com/wp-json

    {"name":"Stern Data Solutions","description":"Technology, Web Sites and More","url":"https:\/\/www.sterndata.com","home":"https:\/\/www.sterndata.com","namespaces":["oembed\/1.0"],"authentication":[],"routes":{"\/":{"namespace":"","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false,"default":"view"}}}],"_links":{"self":"https:\/\/www.sterndata.com\/wp-json\/"}},"\/oembed\/1.0":{"namespace":"oembed\/1.0","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"namespace":{"required":false,"default":"oembed\/1.0"},"context":{"required":false,"default":"view"}}}],"_links":{"self":"https:\/\/www.sterndata.com\/wp-json\/oembed\/1.0"}},"\/oembed\/1.0\/embed":{"namespace":"oembed\/1.0","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"url":{"required":true},"format":{"required":false,"default":"json"},"maxwidth":{"required":false,"default":600}}}],"_links":{"self":"https:\/\/www.sterndata.com\/wp-json\/oembed\/1.0\/embed"}}},"_links":{"help":[{"href":"http:\/\/v2.wp-api.org\/"}]}}

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘"rel='https://api.w.org/' json" website url is wrong’ is closed to new replies.