Clicky

  1. Home
  2. How To
  3. How to modify the In-Content Related Post image loop by using the filter

How to modify the In-Content Related Post image loop by using the filter

If you want to change or modify the width, height and responsive for In-Content Related Post image loop then you need to add below the filter

Example code:

add_filter('ampforwp_modify_inline_rp_loop_image','dummy_function');
function dummy_function($args){
    $thumb_url_2 = ampforwp_get_post_thumbnail('url');
    list($width, $height) = getimagesize($thumb_url_2);  

   $custom_img = preg_replace(
     '/<amp-img src=(.*?)\s(.*)width=(.*?)\s(.*)height=(.*?)\s(.*)layout=(.*?)\s><\/amp-img>/',
      '<amp-img src='.$thumb_url_2.' width='.$width.' height='.$height.' layout="responsive" class="img-cover"></amp-img>', $args);
    

  $custom_changes .= '<div class="image-container-rltd">';
  $custom_changes .= $custom_img;
  $custom_changes .= '</div>';
  $args = $custom_changes;
  return $args;
}

The Output of In-Content Related Post image loop

That’s it for this tutorial!

We hope it helped you. If you have any feedback or questions, then please share them in the comments section below.

Ask your Questions Directly!
If you can't find the solutions in this article, then just ask us in the comments and we will answer it for you!
Updated on May 7, 2020

    Are you still looking for a solution?

    Then fill out the below form and we will reach out to you within a few hours.


    Was this article helpful?

    Related Articles

    Leave a Comment