• Resolved garywiz

    (@garywiz)


    The settings page says that “Default Image to Use” should be … “Full URL including http:// to the default image to use if your posts/pages don’t have a featured image or an image in the content.

    However, that is NOT the way it works. The default image is ADDED to the images for the page, so when you have a featured image, there are two og:image metatags, not one. Facebook (and others) therefore often choose the wrong image.

    I looked at the code and confirmed this, and fixed it as per below, which I believe is what is intended and desirable. Here is the section that selects images after I changed it:

    // Only find images if it isn't the homepage and the fallback isn't being forced
     if ( ! is_home() && $options['wpfbogp_force_fallback'] != 1 ) {
    	 // Find featured thumbnail of the current post/page
    	 if ( function_exists( 'has_post_thumbnail' ) && has_post_thumbnail( $post->ID ) ) {
    		 $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
    		 $link = $thumbnail_src[0];
    		 if ( ! preg_match( '/^https?:\/\//', $link ) ) {
    			 // Remove any starting slash with ltrim() and add one to the end of site_url()
    			 $link = site_url( '/' ) . ltrim( $link, '/' );
    		 }
    		 $wpfbogp_images[] = $link; // Add to images array
    	 }
    
    	 if ( wpfbogp_find_images() !== false && is_singular() ) { // Use our function to find post/page images
    		 $wpfbogp_images = array_merge( $wpfbogp_images, wpfbogp_find_images() ); // Returns an array already, so merge into existing
    	 }
     }
    
     // Make sure there were images passed as an array and loop through/output each
     if ( ! empty( $wpfbogp_images ) && is_array( $wpfbogp_images ) && $options['wpfbogp_force_fallback'] != 1) {
    	 foreach ( $wpfbogp_images as $image ) {
    		 echo '<meta property="og:image" content="' . esc_url( apply_filters( 'wpfbogp_image', $image ) ) . '"/>' . "\n";
    	 }
     } elseif ( isset( $options['wpfbogp_fallback_img'] ) && $options['wpfbogp_fallback_img'] != '') {
    	 echo '<meta property="og:image" content="' . esc_url( apply_filters( 'wpfbogp_image', $options['wpfbogp_fallback_img'] ) ) . '"/>' . "\n";
     } else {
    	 // No images were outputted because they have no default image (at the very least)
    	 echo "<!-- There is not an image here as you haven't set a default image in the plugin settings! -->\n";
     }
Viewing 1 replies (of 1 total)
  • Plugin Author Chuck Reynolds

    (@ryno267)

    it’s the way it is because that used to work for FB. since they’ve changed the way they read the image array.
    If you’re into code feel free to use github. https://github.com/chuckreynolds/WPFBOGP/tree/develop
    There’s a much newer version of this plugin that’s kindof almost ready for prime-time and it handles that default/fallback image much better.
    also the feature/images-overhaul branch.

Viewing 1 replies (of 1 total)
  • The topic ‘"Default Image to Use" doesn't work as documented’ is closed to new replies.