• Resolved jimmiedee

    (@jimmiedee)


    Hello,

    Is it possible to modify the og:url metadata with this plugin?

    I have a lot of old posts that are http. I recently switched to https and now of course Facebook will not serve the count data for the new https url. I believe if I change the og:url of the page from https to http it should then work.

    So what I am looking for is a way to override the og:url that is automatically generated from the page url using some form of edit box.

    Many thanks,
    Jim

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Alex MacArthur

    (@alexmacarthur)

    Hi, Jim —

    There’s no way to change these values using an edit box in the admin, but you can use one of the filters that the plugin exposes. It just requires a little bit of code that would convert all https references to http. Here’s the snippet of the filter I include in the documentation:

    
    function modify_open_graph_data($data) {
      $data['og:site_name']['value'] = 'whatevs';
      return $data;
    }
    add_filter('complete_open_graph_all_data', 'modify_open_graph_data');
    

    I don’t have time to whip up an example for you now, but might be able to get to that later this weekend.

    Thread Starter jimmiedee

    (@jimmiedee)

    Thanks for the reply. I will also take a look. Whilst I am a software developer this is all new to me.

    I need to work out:

    1. Where to put the filter.
    2. How to get the url of the page – I guess it is part of $data[‘og:url’][‘value’]
    3. How to modify the url to replace ‘https’ with ‘http’

    Thanks,
    Jimmie

    Thread Starter jimmiedee

    (@jimmiedee)

    Worked out how to change the url:

    $url = preg_replace(“/^http:/i”, “https:”, $url);

    Just need to know where to put the filter code.

    Does it go in the filters.php file? If so could you supply an example of how to fit it in please?

    Plugin Author Alex MacArthur

    (@alexmacarthur)

    Awesome, now you just need to plug that preg_replace into something like below. I know I mentioned a different filter earlier, but I think this one might be more suitable since you’re only interested in a single field. This filter only deals with the og:url meta field:

    
    add_filter('complete_open_graph_og:url', function($url, $field_name) {
    	$url = preg_replace("/^http:/i", "https:", $url);
      	return $url;
    }, 10, 2);
    

    You’d place this code in your theme’s functions.php file. I wouldn’t recommend modifying the plugin’s files themselves.

    Let me know if that helps!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Change og:url’ is closed to new replies.