• Resolved Rupert121

    (@rupert121)


    I know that SEO by Yoast don’t pay much attention for attachment pages, but I need them for like buttons in my gallery.

    And on those pages (image.php) there is no proper og:image and og:description meta. For image is used default image and not attachment image, and description is blank but can be used image description.

    I have managed to correct meta with jQuery in image.php, but Facebook linter is not reading that.

    I am wondering how I can put it in the SEO plugin to work…

    You can see that here –

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Rupert121

    (@rupert121)

    I have managed getting the right og:image meta.

    In class-opengraph.php change line 233 to look like this:

    if ( is_singular( 'attachment' ) ) {
      $url = wp_get_attachment_url ( $post->ID );
      if ( $url ) {
         echo "<meta property='og:image' content='" . $url . "'/>\n";
      }
    } else {
     echo "<meta property='og:image' content='" . esc_url( $img ) . "'/>\n";
    }

    It will put the curent image link on attachment page to og:image.

    What I need is og:description – I have managet to put image description to og:description, but what I really want is to use parent page og:description. So – help please!

    Thread Starter Rupert121

    (@rupert121)

    OK… I came up with code for og:description to show image description on attachment pages. If anybody needs this…

    Just in class-opengraph.php change this code below the line 284:

    $ogdesc = apply_filters( 'wpseo_opengraph_desc', $ogdesc );
    
    if ( $ogdesc && $ogdesc != '' ) {
      if ( $echo !== false )
        echo "<meta property='og:description' content='" . esc_attr( $ogdesc ) . "'/>\n";
        else
          return $ogdesc;
    }

    to this:

    $ogdesc = apply_filters( 'wpseo_opengraph_desc', $ogdesc );
    
    if ( $ogdesc && $ogdesc != '' ) {
      if ( $echo !== false )
        echo "<meta property='og:description' content='" . esc_attr( $ogdesc ) . "'/>\n";
      else
       return $ogdesc;
      } elseif ( is_home() ) {
        echo "<meta property='og:description' content='YOUR CUSTOM CODE FOR FRONT PAGE (still don't know how to call SEO description)'/>\n";
      } elseif ( is_singular( 'attachment' ) ) {
        $description = $post -> post_content;
        if ( $description ) {
          echo "<meta property='og:description' content='" . $description . "'/>\n";
        } else {
          echo "<meta property='og:description' content='YOUR CUSTOM CODE IF YOU DIDN't SET IMAGE DESCRIPTION'/>\n";
        }
    }

    Hey, thanks for posting this. I was pulling my hair out over that one. However, you are referring to line 233 for the images – depending on which editor I am using the line numbering is different.

    Can you post a code excerpt of the class-opengraph.php where that code has to go? THANK YOU !

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: WordPress SEO by Yoast] No proper social meta on attachment pages’ is closed to new replies.