Advertisement
utnalove

content

Dec 17th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <?php // In order to give the right rich snippets required by google snippets validator
  2. if ( has_post_thumbnail() ) : // check if the post has a Post Thumbnail assigned to it.
  3.  
  4. $upload_dir = wp_upload_dir();
  5.  
  6. $size = 'large';
  7.  
  8. $post_thumbnail_id = get_post_thumbnail_id( $post_id );
  9. $post_thumbnail_meta = wp_get_attachment_metadata ( $post_thumbnail_id );
  10. $main_file = $post_thumbnail_meta [ 'file' ];
  11. $dirname = dirname ( $main_file );
  12. $base_url = trailingslashit ( $upload_dir['baseurl'] ) . $dirname . '/';
  13. $filename = $post_thumbnail_meta [ 'sizes' ][ $size ][ 'file' ];
  14. $width = $post_thumbnail_meta [ 'sizes' ][ $size ][ 'width' ];
  15. $height = $post_thumbnail_meta [ 'sizes' ][ $size ][ 'height' ];
  16. $file = $base_url . $filename;
  17. ?>
  18. <div itemprop="image" itemscope itemtype="https://schema.org/ImageObject">
  19.     <meta itemprop="url" content="<?php echo $file; ?>">
  20.     <meta itemprop="width" content="<?php echo $width; ?>">
  21.     <meta itemprop="height" content="<?php echo $height; ?>">
  22.     <?php
  23.       if ( has_post_thumbnail() ) {
  24. the_post_thumbnail( 'full', array('class'=>'post_thumbnail_common', 'alt' => get_the_title() , 'title' => get_the_title() ));
  25. echo contentnoimg(41);} else { echo content(41); } ?>
  26.  
  27. </div>
  28. <?php
  29.  
  30. endif;
  31.  
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement