Advertisement
teastudio

wpc_item_featured_image with custom field from acf

Aug 24th, 2016
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. function my_wpc_item_featured_image( $featured_image, $params ) {
  2.     $new_image_url = get_field( 'carousel_image', $params['post']->ID );
  3.  
  4.     if ( $params['params']['show_featured_image'] === 'true' && $new_image_url !== false) {
  5.         $data_src = 'src="' . $new_image_url . '"';
  6.         $image_class = null;
  7.  
  8.         if ($params['params']['lazy_load'] === 'true') {
  9.             $data_src = 'data-src="' . $new_image_url . '" data-src-retina="' . $new_image_url . '"';
  10.             $image_class = 'class="owl-lazy"';
  11.         }
  12.  
  13.         $featured_image = '<div class="wp-posts-carousel-image">';
  14.             $featured_image.= '<a href="' . $params['post_url'] . '" title="' . __('Read more', 'wp-posts-carousel') . ' ' . $params['post']->post_title . '">';
  15.                 $featured_image.= '<img alt="' . $params['post']->post_title . '" style="max-width:' . $params['params']['image_width'] . '%;max-height:' . $params['params']['image_height'] . '%" ' . $data_src . $image_class . '>';
  16.             $featured_image.= '</a>';
  17.         $featured_image .= '</div>';
  18.     }
  19.     return $featured_image;
  20. }
  21. add_filter('wpc_item_featured_image', 'my_wpc_item_featured_image', 1, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement