Change image link and html with filter
-
I am trying to replace the link on the featured with a url in a custom field. I am using the ACF custom fields plugin for the custom field. My code is below but the params ‘image_width’ and ‘image_height’ are coming out empty in the html. So I must be missing something but I am not sure what. Can you give me some advice?
function new_link_image( $image, $params ) { $sponsorurl = get_field('sponsors_link',$post->ID); $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID) , $params['image_source']); $data_src = 'src="' . $image[0] . '"'; $image_class = null; $featured_image = '<div class="wp-posts-carousel-image">'; $featured_image.= '<a href="' . $sponsorurl . '" title="'. $params['post']->post_title . '">'; $featured_image.= '<img alt="' . $params['post']->post_title . '" style="max-width:' . $params['image_width'] . '%;max-height:' . $params['image_height'] . '%;" ' . $data_src . $image_class . '>'; $featured_image.= '</a>'; $featured_image.= '</div>'; $featured_image .= 'sponsorurl=' . $sponsorurl; return $featured_image; } add_filter('wpc_item_featured_image', 'new_link_image', 1, 2);
The above code is outputting the following html:
<div class="wp-posts-carousel-image"> <a title="Telitec" href=""> <img src="https://~/telitec-wide.png" style="max-width:%;max-height:%;" alt="Telitec"> </a> </div>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Change image link and html with filter’ is closed to new replies.