Setup Filter to change OpenGraph URL ( og:url )

  • Hi,
    I am changing my whole website to https instead of http. (this is my site
    This means my Facebook Comments and all share counts (FB, Pinterest etc.) will not load anymore(collected over 9 years).
    I found your page about Filters (

    Filter to change OpenGraph URL ( og:url ).
    * Allows the output of the canonical URL as OpenGraph URL, consolidating likes and shares.
    * @link
    * @param $url Canonical URL
    add_filter( ‘rank_math/opengraph/url’, function( $url ) {
    return $url;

    Can you explain how I would get this to work?

    I understand how to create the functions file rank-math.php.

    But do I have to change the canonical url in all posts (95 posts and pages) to the http url first?

    Or would I create a list of all 95 post urls, and then add that add_filter code to the rank-math.php file for 95 lines with the urls?

    I read changing canonical urls for every url might have a problem – “However, this might not be ideal as the canonical URL wouldn’t output the correct reflection of it being HTTPS.”

    Also, I hope it would work with Elementor Pro and the share button plugin…

    FYI this is the official Facebook method:

    Thank you!

Viewing 9 replies - 16 through 24 (of 24 total)
  • Thank you, but, sadly, I am not seeing the Facebook Comments in the https post 🙁 This post has 33 comments, and when you load the page you can scroll to the bottom and see that none of them show. 🙁 🙁 🙁

    I don’t understand coding so I can’t read those links and know what to do with them myself though…


    Upon checking further, we have figured out that the comments are being managed by the data-href tag that is being added by Elementor. The issue has nothing to do with the og:url tag:

    So you should get in touch with Elementor support and ask them to help you modify the data-href tag. You can also remove the code that I have added in the rank-math.php file.

    Let us know how that goes. Looking forward to your update.


    Oh that is unfortunate. I will contact them. Thank you for letting me know! I appreciate it! I will let you know what they say.


    Sure, keep us in the loop and if you need any other assistance from our side don’t hesitate to get in touch.

    We are here to help!

    I added the plugin Fancy Facebook Comments and that fixed the problem.


    We apologize for the unexpected delay. I am glad that you are able to fix this issue by installing that specific plugin. Do you need further assistance?

    We are looking forward to helping you.

    No, it seems to be fine now. Perhaps take note of the solution for the future.


    We are super happy that your issue is resolved and thanks for sharing the solution with us. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 9 replies - 16 through 24 (of 24 total)

You must be logged in to reply to this ticket.