Using Change OG URL To HTTP with Rank Math

#35166
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting Rank Math today.

    I have just tested this plugin but it does not have native support for Rank Math. You can however add the following code snippet on your theme’s functions.php file to remove the HTTPs on OG:URL:

    /**
     * Allows the output of the canonical URL as OpenGraph URL, consolidating likes and shares.
     *
     * @link https://developers.facebook.com/docs/reference/opengraph/object-type/article/
     * @param $url Canonical URL
     */
    add_filter( 'rank_math/opengraph/url', function( $url ) {
            $ogurl = explode( ':', $url);
    	$ogurl_part = $ogurl[1];
    	$ogurl = 'http:' . $ogurl_part;
    				
    	return $ogurl;
    });

    You can then follow the rest of the steps from the plugin author:

    Step 2: If you are using a Cache plugin (eg: WP Super Cache), delete the cache.

    Step 3: Exclude facebook bot from the HTTP to HTTPS redirection in your HTaccess file. Here’s an example:

    RewriteEngine On
    RewriteCond% {SERVER_PORT} 80
    RewriteCond% {HTTP_USER_AGENT}! Facebookexternalhit / [0-9]
    RewriteRule ^ (. *) $ https://sitename.com/$1 [R = 301, L]

    The above rewrite rule excludes facebook bots from the redirect.

    Step 4: Wait for 30 days for facebook to resize your pages. Your ‘share count’ will return when facebook rescrapes your page.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hi,

    Will this solution change the OG URL of EVERY post? I need the function of the “Change OG URL To HTTP” plugin that only changes posts set before the plugin was installed.

    Hi there,

    Thanks for the follow up.

    Yes this will change the canonicals for all URLs but you can add a conditional to check the post dates.
    From what I could gather from the functionality of the plugin, it changes all canonicals for all post that existed before changing to to an SSL version of the site.

    I hope this info helps.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘Using Change OG URL To HTTP with Rank Math’ is closed to new replies.