WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
OpenGraph Issue when also using SEO with Root Relative URLs plugin (19 posts)

  1. mjm4842
    Member
    Posted 1 year ago #

    ==> WordPress version: 3.4.2
    ==> WordPress SEO version: 1.2.8.7

    ==> I did this:

    Note that I have the Root Relative URLs plugin well as a plugin that lets me place a Facebook Like button on my page (have tried several actually). It first came to my attention while troubleshooting an issue with Facebook Like counters using the Facebook Developer's Debugger.

    ==> I expected the plugin to do this:

    I expected the plugin to generate the correct code regardless of what other plugins might be installed. Example:

    <meta property='og:url' content='http://www.yoursite.com/'/>

    While I realize that Root Relative URLs plugin is at the root of the problem, it is crucial that WordPress SEO take the initiative to ensure all URL's are complete.

    This is especially important in instances where the information is a link that another site, like Facebook, will be using to refer back to your website.

    ==> Instead it did this:

    With the Root Relative URLs plugin installed, WordPress SEO generates the following OpenGraph line of code:

    <meta property='og:url' content='/'/>

    ==> Here is how to fix the problem

    In the case of og:url, it is possible to fix the OpenGraph og:url meta property by editing the file named wp-content/plugins/wordpress-seo/frontend/class-opengraph.php and replace this line...

    echo "<meta property='og:url' content='" . esc_attr( $this->canonical( false ) ) . "'/>\n";

    ... with the following two lines ...

    $SiteRoot = (substr(esc_attr( $this->canonical( false ) ),0,1) == '/' ? (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https" : "http") : '') . "://" . $_SERVER['HTTP_HOST'];
    echo "<meta property='og:url' content='". $SiteRoot . esc_attr( $this->canonical( false ) ) . "'/>\n";

    Please fix this problem as soon as possible. Until this fix is included in WordPress SEO, folks will always have to remember to apply the fix each time they update the WordPress SEO plugin.

    ==> So why is this important to me?

    Facebook makes use of the 'og:url' meta property.

    Unfortunately you won't see the problem on my site (http://www.tngconsulting.ca) unless I forget to re-apply the fix after updating WordPress SEO. That being said, I would be happy to assist the developers of WordPress SEO with this reproducible issue.

    Best regard,

    Michael Milette

    http://wordpress.org/extend/plugins/wordpress-seo/

  2. mjm4842
    Member
    Posted 1 year ago #

    Correction - The two lines should be:

    $SiteRoot = (substr(esc_attr( $this->canonical( false ) ),0,1) == '/' ? 'http'.(@empty($_SERVER['HTTPS'])?'':'s').'://'.$_SERVER['SERVER_NAME'].( $_SERVER['SERVER_PORT']!=='80' && $_SERVER['SERVER_PORT']!=='443' ? ':'.$_SERVER['SERVER_PORT'] : '') : '');
    echo "<meta property='og:url' content='". $SiteRoot . esc_attr( $this->canonical( false ) ) . "'/>\n";

    These fix a bug and take the port into consideration if it isn't the standard 80 or 443.

    Micheal Milette

  3. RoamFree
    Member
    Posted 1 year ago #

    I hope that this gets improved. I often have to deal with root/relative URLs as part of WP site migrations.

  4. brett cairns
    Member
    Posted 1 year ago #

    same problem. wordpress seo generates the following code <meta property='og:url' content=''/> without adding the site url so facebook open graph debug states that the object is invalid because the given value '' for property 'og:url' could not be parsed as type 'url'. Not really interested in trying to re-wrote the plugin code as suggested above. Hopefully a fix is in the works for this great product.

  5. alesub
    Member
    Posted 1 year ago #

    Same problem over here. I'm just hacking the code after each update to fix this manually.

  6. brett cairns
    Member
    Posted 1 year ago #

    what change are you making to the code?

  7. alesub
    Member
    Posted 1 year ago #

    In the file /wordpress-seo/frontend/class-opengraph.php, around line 134 look for the function called public function url(), replace it with this:

    public function url() {
        $url = 'http://'.$_SERVER["SERVER_NAME"].$_SERVER['REQUEST_URI'];
        echo "<meta property='og:url' content='" . $url . "'/>\n";
    }
  8. brett cairns
    Member
    Posted 1 year ago #

    tired and the file transfer failed citing permission denied.

  9. alesub
    Member
    Posted 1 year ago #

    That's an issue regarding the file permissions on your server, you should try with the main user for the account, or contact the hosting guys if you were using the main account already.

  10. brett cairns
    Member
    Posted 1 year ago #

    reset the permissions and it worked but with one small glitch.

    my site format is http://www.mysite.com and the url used was http://www.mysite.com/

    Is there any way of modifying the code to eliminate the trailing slash?

  11. alesub
    Member
    Posted 1 year ago #

    try replacing

    'http://'.$_SERVER["SERVER_NAME"]

    with

    get_bloginfo('url')

  12. brett cairns
    Member
    Posted 1 year ago #

    same result - url still has the /

  13. RoamFree
    Member
    Posted 1 year ago #

    Brett,

    Go to yoursite/wp-admin/options-general.php

    See if you typed the trailing slash in the URL for "WordPress address" or "Site address".

  14. brett cairns
    Member
    Posted 1 year ago #

    no / there and I added a filter so WP SEO does not add it. I have a rel canonical meta tag in the head so may not be a big deal but would be nice to not have it show in the og meta data. Maybe this is the default for WP?

  15. alesub
    Member
    Posted 1 year ago #

    The slash is coming from the $_SERVER['REQUEST_URI'] variable.

    Maybe you can add an if statement to check if the current page is the home:

    if(is_home())
        $url = get_bloginfo('url');
    else
        $url = 'http://'.$_SERVER["SERVER_NAME"].$_SERVER['REQUEST_URI'];
  16. brett cairns
    Member
    Posted 1 year ago #

    Perfect! Worked great. Thanks for all your help on this

  17. RoamFree
    Member
    Posted 1 year ago #

    Well, apparently PHP is emitting the slash from SERVER_NAME or REQUEST_URI.
    http://php.net/manual/en/reserved.variables.server.php

    If it's not coming from REQUEST_URI, you'll need to invoke a string function to strip off the undesired character.

  18. alesub
    Member
    Posted 1 year ago #

    :)

  19. mjm4842
    Member
    Posted 1 year ago #

    Great, now that we have a working fix, can we get it included in the next release of WordPress SEO please?

    I keep forgetting to go apply the fix each time I update the plugin on my site.

    Michael Milette

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic