Support » Plugin: Jetpack by WordPress.com » Sharing: Social share counts are gone

Viewing 15 replies - 1 through 15 (of 25 total)
  • Plugin Contributor Jeremy Herve

    (@jeherve)

    Jetpack Mechanic πŸš€

    Twitter, G+, everything is gone.

    That’s indeed to be expected. Twitter does not offer any way to count shares anymore, the API allowing us to get sharing counts was deprecated last year. Google+, on the other end, is not supported by Jetpack. It’s on our roadmap though, and you can follow our progress here:
    https://github.com/Automattic/jetpack/issues/584

    Facebook, on the other end, should work. Unfortunately, and as you mentioned, Facebook sometimes treats HTTP and HTTPS differently. That’s something we’ve discussed with Facebook directly, but unfortunately nothing has changed yet. You can follow our discussion about this issue here:
    https://github.com/Automattic/jetpack/issues/2536

    Until Facebook fixes this issue, you could try to follow Facebook’s documentation where they describe workarounds for preserving counts when a URL changes:
    https://developers.facebook.com/docs/sharing/webmasters/crawler#updating

    joxocafeco

    (@joxocafeco)

    Oh I see…

    Just to be sure, https://developers.facebook.com/docs/sharing/webmasters/crawler#updating there is nothing that I can do other than to follow the advice on this URL?

    Also, what about Pinterest? I am absolutely sure it used to show me the share count for Pinterest but now is not.

    Plugin Contributor Jeremy Herve

    (@jeherve)

    Jetpack Mechanic πŸš€

    there is nothing that I can do other than to follow the advice on this URL?

    That’s correct!

    Also, what about Pinterest? I am absolutely sure it used to show me the share count for Pinterest but now is not.

    Pinterest and LinkedIn should still work. Both networks should handle share counts for both http and https. You can check it by querying their API directly, like Jetpack does. Just add a post URL to the end of those URLs:

    https://api.pinterest.com/v1/urls/count.json?callback=WPCOMSharing.update_pinterest_count&url=

    https://www.linkedin.com/countserv/count/share?format=jsonp&callback=updateLinkedInCount&url=

    cuenca

    (@cuenca)

    Thank you for this information and for the link to the Facebook documentation. Could you show an example of how to write the instruction in .htaccess to exempt the Facebook crawler from a 301 direct? I’ve not found a way to do this properly.

    The Facebook solution also calls for using og:url tags in the old and new pages. What’s the best way to implement this in WordPress?

    In my case, rather than having URL changes because of a switch to SSL, I want to combine two WordPress installations One is in a subdomain. I want to import the blog posts from the subdomain into the main site’s WordPress installation, eliminate the subdomain, and use the 301 redirects to point to the new URLS for the posts moved out of the subdomain. I eventually also would like to go to SSL but am not ready to do that yet.

    Thanks!

    Plugin Contributor Jeremy Herve

    (@jeherve)

    Jetpack Mechanic πŸš€

    Could you show an example of how to write the instruction in .htaccess to exempt the Facebook crawler from a 301 direct? I’ve not found a way to do this properly.

    In your case, it might be easier to change the og:url value.

    If you use Jetpack to add the Jetpack Open Graph Meta Tags to your site, you can use the jetpack_open_graph_tags filter to change the output of the og:url tag to use HTTP instead of HTTPS.

    Here are a few examples on how to use that filter:
    https://developer.jetpack.com/hooks/jetpack_open_graph_tags/

    cuenca

    (@cuenca)

    Thanks, Jeremy. BTW, I’m not trying to hijack this topic instead of starting a new one. I’m just trying to see if we can figure out how to follow the Facebook documentation at the link you provided above to successfully implement that solution for preserving social share counts in WordPress when we have 301 redirects.

    That Facebook documentation says that I have to both exempt the Facebook crawler from the 301 redirect and include og:url tags in both the old and new pages. The way I am reading it, both the old page and new page must include:
    <meta property=”og:url” content=”https://example.com/old-url” />
    AND the 301 redirect for the old page must exempt the old page so that the old page may be successfully accessed.

    So I still need to learn how to exempt the Facebook crawler from the 301 redirects. Do you have any idea how to do that?

    For the old pages, I believe I could follow your suggestion to properly use the Jetpack Open Graph Meta Tags for the og:url tag. For the new pages (posts), however, I will only have corresponding old pages for those coming from the 301 redirects. I’m not sure how I could add the URL for the old page into an og:url tag only into the set of pages (posts) that are the destinations of the 301 redirects without having to insert the og:url tags individually somehow. In other words, pages (posts) imported into the main site’s WordPress installation would be the only ones needing this og:url tag that points to an old URL.

    Plugin Contributor Jeremy Herve

    (@jeherve)

    Jetpack Mechanic πŸš€

    That Facebook documentation says that I have to both exempt the Facebook crawler from the 301 redirect and include og:url tags in both the old and new pages.

    You’re right, my bad. I assumed that doing only one would be enough, but it doesn’t look like it is.

    I’m not sure I’ll be able to help much with the redirect though, as it really depends on how you redirect HTTP to HTTPS right now. Will you set up custom redirect rules in .htaccess? Will you use a plugin to handle the redirections for you? Will you use a reverse proxy to make the redirection before the requests hit your site?

    Depending on your SSL implementation, you’ll need to take a different approach to exempt the Facebook bot from your redirections.

    If you implement the initial redirection via .htaccess, this will help:
    http://stackoverflow.com/a/19165071/1045686

    However, it’s worth noting that Facebook is known to not always use a User Agent when crawling your site. As a result, regardless of the way you implement that custom rule for Facebook, it won’t always work.

    I hope this helps.

    cuenca

    (@cuenca)

    Thanks, Jeremy. I was planning to put the redirection into .htaccess directly. The info at the stackoverflow link looks promising. Thanks for the pointer to it.

    Inserting the og canonical URL as described in https://developers.facebook.com/docs/sharing/webmasters/crawler#updating does not work.

    Here is my code, it works as expected, but Facebook does not show the share counts from the old http URL.

    
    //Add facebook og: canonical to http (after https migration)
    
    function add_http_to_fb_og_canonical() {
        // Get current URL
        $url = $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
     
        // Get HTTP version of URL
        $url = preg_replace( '/https:/i', 'http:', $url );
     
        echo '<meta property="og:url" content="'.$url.'" />';
    }
    add_action('wp_head', 'add_http_to_fb_og_canonical');
    
    

    I can’t believe Facebook isn’t dealing with this problem yet, it would be so easy for them to solve.

    theguitarlesson

    (@theguitarlesson)

    I managed to figure this out, it sure took a while. Just a heads up, the 301 redirect you implement also messes up the Facebook and Google +1 count.
    I wrote a case study on all of the issues I had during the https migration where I discuss the details, hopefully it will be useful to others in my shoes:
    https://www.theguitarlesson.com/guitar-lesson-blog/theguitarlessoncom-news/https-migration/

    Thank you, @theguitarlesson, for writing up your experience and lessons learned. I had intended to make my switch to SSL right after the start of the year. However, it has been delayed. I’m getting ready to do it now. So it’s really nice to read how it went for you and how you resolved issues along the way.

    Just to be clear, though, with respect to Facebook’s instructions ( https://developers.facebook.com/docs/sharing/webmasters/crawler#updating ), it will work if you follow the two steps to the letter, right?

    1. Exempt the Facebook crawler from your HTTP redirect
    — It looks like you’ve done this. Also, this requires you to keep every old URL alive with a page or post with og:url tag pointing to itself.

    2. Use the old page as the canonical URL for the new page
    — In this case, the page or post at each new URL must include an og:url tag that points to the corresponding old URL.

    According to Facebook, following these two steps should result in the share count at the new URL reflecting the combined share totals from both the old and new. Is that what finally ended up working for you?

    What’s the preferred method for adding all of these og:url tags? Clearly, only 301 redirected posts/pages will need to have the old/new pairs of og:url tags. New posts/pages won’t need them. So it looks to me like each pair of redirected posts/pages will need to have custom, individual og:url tags inserted.

    Thanks again for the great article!

    • This reply was modified 8 months, 1 week ago by  cuenca.

    Hi @cuenca, I’m glad you find my article useful. It was pretty complicated figuring everything out, that’s why I wrote the article. And to have it ready next time I need to migrate a site.

    So anyhow, your questions:
    1. Yes, the key element in all this is exempting the FB crawler from the 301 redirect. The code is in my article.

    2. I didn’t use the og:canonical method. I tried it initially with the code in a reply above, but it didn’t work at all for me. When I tried it, the FB redirect exemption was not in place yet, but I don’t think that has anything to do with it not working, since the FB crawler didn’t recrawl the URL yet. So basically I just don’t think the og:canonical method works.

    Instead, I just use the old non-HTTPS URL in the facebook like box. The disadvantage of this is that the new HTTPS URL does not gain any likes, but I’m counting on FB to fix this whole problem sometime in the future, and than this all won’t matter.

    Thanks again, @theguitarlesson . Your guide is proving to be very useful!

    cuenca

    (@cuenca)

    Jeremy, @jeherve ,

    After all this time, I’ve just recently tried to implement the Facebook share counts solution for switching from http to https. My case has some extra complications because I’m also migrating 202 posts from one WordPress installation into another at the same time as switching from http to https.

    At this time, I’m stalling out on how to handle this requirement from https://developers.facebook.com/docs/sharing/webmasters/crawler#updating :
    —-
    2. Use the old page as the canonical URL for the new page

    Add this tag to the HTML of the new URL:

    <meta property=”og:url” content=”https://example.com/old-url” />

    This tells our crawler that the canonical URL is at the old location, and the crawler will use it to generate the number of Likes on the page. New likes at either location will aggregate in both places.
    —-

    You earlier suggested using a filter to modify og:url in the Jetpack Open Graph Meta Tags. From what I see, that will only provide for a generic override that will apply to all posts/pages. I think I would need to custom set the og:url for individual posts/pages, depending on the case. I will have three cases:

    1. migrated posts that have URL changes in addition to the https change
    EXAMPLE:
    OLD URL: http://blog.domain.com/yyyy/mm/dd/post slug/
    NEW URL: https://www.domain.com/post slug/
    (I have 202 of these.)

    2. existing posts/pages that are only changing from http to https
    EXAMPLE:
    OLD URL: http://www.domain.com/post slug/
    NEW URL: https://www.domain.com/post slug/

    3. new posts created after the https migration that will not need a modified og:url tag

    It seems to me that the only way to handle this would be to have the capability to specify the needed og:url tag for each affected post/page in the editor. I can’t find any plugin that will provide this functionality. Is the only solution for me to create my own plugin for this? I’ve never created a plugin before and there will be a learning curve for me. What’s your recommended solution?

    Thanks!

    Plugin Contributor Jeremy Herve

    (@jeherve)

    Jetpack Mechanic πŸš€

    You could indeed build your own plugin, and rely on WordPress’ custom fields to define a custom og:url tag for each one of your posts.

    If you would like to learn how to build your own plugins, you can check this Codex page:
    https://developer.wordpress.org/plugins/

    If you’d rather skip to the end, I created a plugin for you, that should do the trick. You can check the code here:
    https://github.com/jeherve/jeherve-custom-ogurls/blob/master/jeherve-custom-ogurls.php

    I commented it and broke it down as much as possible so it’s a bit easier to understand what each part does.

    You can install the plugin on your site by downloading this zip file, and then going to Plugins > Add New > Upload to upload it to your site.

    To use the plugin, you can follow the instructions here:
    https://github.com/jeherve/jeherve-custom-ogurls/blob/master/README.md

    I hope this helps.

Viewing 15 replies - 1 through 15 (of 25 total)
  • You must be logged in to reply to this topic.