Support » Plugin: Yoast SEO » filter "wpseo_opengraph_image" Twitter VS Facebook inconsistency

  • ladislav.soukup


    WordPress version: 3.5
    WordPress SEO version:

    I have one custom post type that is loading data from external API and is not using integrated post thumbnail. I’m trying to override the og:image and twitter:image tags (I have default images set).

    I have found a very useful filter “wpseo_opengraph_image” in the source code, but there is “bug” or inconsistency between “class-opengraph.php” and “class-twitter.php”.

    Opengraph class is trying to fetch image from post_thumbnail, then load default and then it is applying the filter, so image can be rewritten in all cases.
    Twitter class is first doing the check if post_thumbnail exists and then rewrite can be applied to override the post_thumbnail, but if no post thumbnail exists, class will use the default image without using the filter “wpseo_opengraph_image”, so no rewrite option exists.

    In short…
    If there is no post_thumbnail, “wpseo_opengraph_image” filter is working on open graph tag, but is not working on twitter:image tag.

    This is not a show-stopper and I can “fix” the code for now.
    Please try to look at it, it seems, that opengraph class is newer then twitter class 😉

Viewing 1 replies (of 1 total)
  • ladislav.soukup



    this “fix” of public function image() in class-twitter.php is working

    * Displays the image for Twitter
    * Only used when OpenGraph is inactive.
    public function image() {
    	global $post;
    	if ( function_exists( 'has_post_thumbnail' ) && has_post_thumbnail( $post->ID ) ) {
    		$featured_img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), apply_filters( 'wpseo_opengraph_image_size', 'medium' ) );
    		if ( $featured_img ) {
    			$img = apply_filters( 'wpseo_opengraph_image', $featured_img[0] );
    			echo "<meta name='twitter:image' content='" . esc_attr( $img ) . "'>\n";
    	} else {
    		$options = get_wpseo_options();
    		if ( isset( $options['og_frontpage_image'] ) && !empty( $options['og_frontpage_image'] ) )
    			$img = apply_filters( 'wpseo_opengraph_image', $options['og_frontpage_image'] );
    			echo "<meta name='twitter:image' content='" . esc_attr( $img ) . "'>\n";
Viewing 1 replies (of 1 total)
  • The topic ‘filter "wpseo_opengraph_image" Twitter VS Facebook inconsistency’ is closed to new replies.