"Default Image to Use" does not work as documented
-
The settings page says that “Default Image to Use” should be … “Full URL including https:// 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 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘"Default Image to Use" does not work as documented’ is closed to new replies.