Advertisement
Guest User

Untitled

a guest
Sep 28th, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.73 KB | None | 0 0
  1. add_filter( 'post_thumbnail_html', 'nelioefi_replace_thumbnail', 10, 5 );
  2. function nelioefi_replace_thumbnail( $html, $post_id, $post_image_id, $size, $attr ) {
  3.     if ( uses_nelioefi( $post_id ) ) {
  4.         $image_url = get_post_meta( $post_id, '_nelioefi_url', true );
  5.         global $_wp_additional_image_sizes;
  6.  
  7.         if ( is_array( $size ) ) {
  8.             $width = $size[0];
  9.             $height = $size[1];
  10.         }
  11.         else if ( isset( $_wp_additional_image_sizes[ $size ] ) ) {
  12.             $width = $_wp_additional_image_sizes[ $size ]['width'];
  13.             $height = $_wp_additional_image_sizes[ $size ]['height'];
  14.         }
  15.        
  16.         $replaced_image = str_replace("/s0/", "/w".$width."-h".$height."-c/", "$image_url");
  17.         $html = sprintf(' <img src="%s"> ', $replaced_image);
  18.         }
  19.     return $html;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement