Connect with us

    Hi, what are you looking for?

    Devs

    How to Solve the Problem of the Image Not Appearing When Sharing a Post in WordPress

    How to Solve the Problem of the Image Not Appearing When Sharing a Post in WordPress

    One of the common frustrations for WordPress users is when the image doesn’t appear correctly when sharing a post on social media. This issue can affect how your content is displayed and perceived by your audience, potentially reducing engagement. Fortunately, there are several ways to troubleshoot and resolve this problem. In this post, we’ll walk you through the steps to ensure that your images appear correctly when sharing posts in WordPress.

    Common Causes of Missing Images

    Before diving into the solutions, it’s important to understand the common reasons why an image might not appear when sharing a post:


    1. Missing or Incorrect Open Graph Tags: Social media platforms rely on Open Graph (OG) tags to determine which image, title, and description to display. If these tags are missing or incorrect, the image may not appear.
    2. No Featured Image Set: If your post doesn’t have a featured image set, platforms like Facebook may not know which image to use.
    3. Image Size Issues: Some social media platforms have specific requirements for image dimensions. If the image is too small or doesn’t meet the minimum size requirements, it might not be displayed.
    4. Caching Problems: If your site uses caching and you’ve recently updated the featured image or post content, the old version might still be cached, causing the wrong image to appear.
    5. Conflicts with Plugins or Themes: Sometimes, other plugins or the theme itself might interfere with how images are displayed or how Open Graph tags are generated.

    Step-by-Step Solutions

    Here’s how you can troubleshoot and fix the problem of images not appearing when sharing a post in WordPress:

    1. Ensure Open Graph Tags Are Present

    Open Graph tags are crucial for controlling how your content is displayed on social media platforms. Without them, platforms may struggle to identify the correct image.

    • Use an SEO Plugin: Plugins like Yoast SEO or All in One SEO automatically add Open Graph tags to your posts. Ensure that these plugins are configured correctly to include the featured image in the OG tags.

    2. Set a Featured Image for Every Post

    A featured image is often the default image used by social media platforms when sharing your content. Here’s how to ensure it’s set:

    • Set the Featured Image: When creating or editing a post, ensure that a featured image is set in the sidebar under the “Featured Image” section.
    • Fallback Image: If you frequently forget to set a featured image, consider using a plugin that automatically assigns a fallback image if none is set.

    3. Adding the Code to Your Theme

    Now that you understand the importance of Open Graph tags, let’s add the necessary code to your theme’s functions.php file. If you’re using a child theme, add the code to the child theme’s functions.php file to ensure your changes are not overwritten during future updates to the parent theme.


    1. Access the WordPress Dashboard and go to Appearance > Theme Editor.
    2. Select the functions.php file of your theme or child theme.
    3. Add the following PHP code at the end of the file:
    4. function add_opengraph_tags() {
      if (is_single() || is_page()) {
      global $post;
      if (has_post_thumbnail($post->ID)) {
      $img_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), ‘full’);
      } else {
      // Default image URL if the post has no featured image
      $img_src = array(‘https://www.example.com/default-image.jpg’);
      }// Post title
      $title = get_the_title();
      // Post description
      $description = get_the_excerpt();echo ‘<meta property=”og:title” content=”‘ . esc_attr($title) . ‘”/>’;
      echo ‘<meta property=”og:description” content=”‘ . esc_attr($description) . ‘”/>’;
      echo ‘<meta property=”og:image” content=”‘ . esc_url($img_src[0]) . ‘”/>’;
      echo ‘<meta property=”og:url” content=”‘ . get_permalink() . ‘”/>’;
      echo ‘<meta property=”og:type” content=”article”/>’;
      }
      }
      add_action(‘wp_head’, ‘add_opengraph_tags’);

    Code Explanation:

    • add_opengraph_tags(): This function checks if the current page is a post or page and, if so, generates the appropriate Open Graph tags.
    • Featured Image:
      • has_post_thumbnail($post->ID): Checks if the post has a featured image set.
      • wp_get_attachment_image_src(): Retrieves the full-size URL of the featured image. If the post does not have a featured image, a default image is used.
    • Title and Description:
      • get_the_title() and get_the_excerpt(): Retrieve the post title and description, which are used for the og:title and og:description tags, respectively.
    • Canonical URL and Content Type:
      • get_permalink(): Retrieves the URL of the current post for the og:url tag.
      • og:type: Set to “article” to indicate that the content is an article.

    4. Clear Caches

    If you’ve made changes to your post or image but the old image is still appearing, it might be due to caching.

    • Clear Your Site’s Cache: If you’re using a caching plugin, clear the cache after making changes to ensure that the updated version is served to users.
    • Use Facebook’s Sharing Debugger: Facebook caches the OG tags for a URL. Use the Facebook Sharing Debugger to refresh Facebook’s cache for your post.

    5. Check for Plugin or Theme Conflicts

    Sometimes, other plugins or your theme might interfere with how images are handled. Here’s how to troubleshoot:

    • Disable Conflicting Plugins: Temporarily disable any plugins that might interfere with image handling or SEO, such as multiple SEO plugins, and check if the issue persists.
    • Switch to a Default Theme: Temporarily switch to a default WordPress theme (like Twenty Twenty-One) to see if the problem is theme-related. If the image appears correctly with the default theme, the issue might be with your current theme.

    Ensuring that the correct image appears when sharing a post on social media is crucial for maximizing engagement and making your content look professional. By following the steps outlined in this article—checking Open Graph tags, setting a featured image, ensuring correct image sizes, clearing caches, and troubleshooting potential conflicts—you can resolve this common WordPress issue.

    If you continue to experience issues, consider consulting a WordPress developer who can help you diagnose and resolve more complex problems. With the right setup, your posts will always look great when shared on social media!

    Photo by Lukas


    Written By

    My name is Juan de Souza, a 25-year-old entrepreneur, investor, blogger, and streamer. My journey in business began at the age of 10, leveraging a dial-up internet connection in Brazil to start my first venture. Currently, I reside in Porto, Portugal, where I have been based since 2025.

    Comments
    Advertisement

    Join Our Discord Server

    Advertisement
    Advertisement

    Recommended Posts for You

    HeartstopperHeartstopper

    LGBTQIA+

    Check out the full review of Netflix's Heartstopper series and find out if the Heartstopper series delivers everything it promises in full!

    Cinema

    “One of the most memorable cartoons of the 20th and 21st centuries. Its story, characters and writing are utterly captivating. “Little Bear” is known...

    Curiosities

    Super Mario World, also known as “Super Mario Bros. 4” in Japan, is without a doubt one of the most popular games of all...

    Cinema

    “Courage the Cowardly Dog” tells the story of Courage, a dog who’s easily scared and lives on a farm with Muriel and Eustace Bagge...

    Cinema

    Who doesn’t know this epic cartoon from Hanna-Barbera, Wacky Races, where eleven competitors vied in every episode for the world title of “World’s Wackiest...

    Cinema

    Sagwa, one of the best cartoons still airing on the Futura channel. In fact, all the shows on Futura are excellent. It tells the...

    Cinema

    “Do you remember the classic cartoon Timon and Pumbaa? It’s an animated TV series produced by Walt Disney Animation, starring the warthog and meerkat...

    Cinema

    At the end of the 1930s, animation was at its peak. It was called the “Golden Age” by many film enthusiasts, where classic characters...

    Cinema

    Woody Woodpecker, one of the most beloved characters of all time. Adored by children, teenagers, and adults alike. The show itself dates back to...

    Curiosities

    Grand Theft Auto V (GTA V) is known for its vast open-world gameplay, where players can explore, complete missions, or just cause chaos. One...

    Others

    “Castelo Rá‑Tim‑Bum” premiered in 1994 on TV Cultura, delighting fans of the original “Rá‑Tim‑Bum” who were tired of its reruns, as well as other...

    Tech

    If you grew up playing console games in the 1980s and 90s and never heard this one, count yourself lucky—very lucky. Here’s the urban...

    DisneyDisney

    Cinema

    Walt Disney, one of the largest and most influential entertainment giants in the world, has a long history of innovation in animation. From its...

    Games

    “Nintendo 64” is Nintendo’s third home video game console. Commonly abbreviated as “N64,” it launched on June 23, 1996 (Japan) and on September 29 in the United States....

    Games

    How about transforming your Minecraft into an even more immersive game? With that in mind, the “Realistico” Mod Pack was developed—a texture pack with...

    Games

    You’ve definitely seen, heard about, or played Just Dance at some point—it’s simply one of the most incredible games ever created and maintained by...

    Games

    Need For Speed Heat has finally hit the streets and is increasingly reminiscent of the franchise’s golden-era titles, such as Need For Speed Underground...

    Games

    It's time to talk about Far Cry 4: a new game in the iconic open-world franchise that first arrived over 10 years ago with paradisiacal...

    Plants vs. Zombies Garden WarfarePlants vs. Zombies Garden Warfare

    Games

    Recently, Plants vs. Zombies Garden Warfare was released—it’s the new game from PopCap, famous for its mobile hits. This time, we have a review...

    What is the Meaning and Function of the Kernel?What is the Meaning and Function of the Kernel?

    Devs

    The kernel is one of the most fundamental components of any operating system (OS), acting as a bridge between the hardware of a computer...