0

I am using this in my functions.php

  add_theme_support( 'post-thumbnails'); 
  set_post_thumbnail_size(); 

  add_image_size( 'post-thumb', 669, 272 );

and in my single.php,home.php and archive.php.. I am using this in loop:

   <?php the_post_thumbnail('post-thumb'); ?>

Now I when I share post to linkedin is used the thumbnail of 669 x 272 dimension but I want to make another custom size of thumbnail e.g 180 x 110 size n force linkedin to use that thumbnail.

thanks in advance.

emppeak
  • 158
  • 12

1 Answers1

0

You will need to use OpenGraph tags to specify content for social media sites to pull from. Documentation.

The OpenGraph tags must go in the <head>. You can make this dynamic by adding something like this to your functions.php:

function add_opengraph() {
    ?>
    <meta property="og:title" content="<?= get_the_title() ?>" />
    <meta property="og:image" content="<?= get_the_post_thumbnail_url( 'small-thumb' ) ?>" />
    <meta property="og:image:width" content="180" />
    <meta property="og:image:height" content="110" />
    <?php
}
add_action( 'wp_head', 'add_opengraph' );

You will of course need to make another thumbnail size just as you did before.

add_image_size( 'small-thumb', 180, 110 );

Two other things you might try debugging:

  1. Try checking with a new page, one that you haven't tested before. It's possible that LinkedIn is caching your old image.
  2. Are you using HTTPS? According to this comment LinkedIn might have trouble crawling HTTPS urls.
rideron89
  • 491
  • 3
  • 14
  • I did create the other thumbnail size with this 'small-thumb' name but in browser source it's still showing the height of the previous one. my code is this in functions.php `add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size(); add_image_size( 'post-thumb', 669, 272, true ); add_image_size( 'small-thumb', 180, 110, true ); function add_opengraph() { ?> – emppeak Jun 21 '17 at 15:19
  • Can you try using Facebook's OpenGraph debugger to see what image they are pulling through? [Link here](https://developers.facebook.com/tools/debug/sharing). – rideron89 Jun 21 '17 at 15:48
  • Also you can check the page source, and see if the opengraph tags are showing up for your post. – rideron89 Jun 21 '17 at 15:50
  • I have Yoast SEO plugin installed.. n it's overriding the height of open graph image.. but it's now showing the height of og nor width when I deactivate my plugin. and yes it's showing the title and image in open graph.. but not including height or width in meta property tags. – emppeak Jun 21 '17 at 16:02
  • You can tell OpenGraph the expected size of the image. I updated my answer. Can you view page source, and confirm the url for the OpenGraph image is correct? – rideron89 Jun 21 '17 at 16:10
  • Yes I did the same n deactivated the YOAST too.. n url is correct and OpenGraph shows the updated width n height too..but when I share on linkedin.. it's now showing full image still.. cropped in half way n not showing some content. – emppeak Jun 21 '17 at 17:17
  • I'm thinking it might be a caching issue with LinkedIn. Can you try testing this with a completely new page? *I updated my answer with this. – rideron89 Jun 21 '17 at 17:33