How to modify the image attributes of Images in content

In this tutorial, we are going to see how to change the layout of the Images present in The Content.

Let’s say you want to change the layout of images from responsive( which is default) to fixed. Then add the below code in your Theme’s functions.php.

add_filter('amp_img_attributes', 'amp_img_new_attrs');

function amp_img_new_attrs($attrs){

 $attrs['layout'] = 'fixed';
 
 return $attrs;
}

With the help of above code, all the images from the content will be changed from layout=responsive to layout=fixed.

If you want to change the layout to fixed-height then add the below code in your Theme’s functions.php

add_filter('amp_img_attributes', 'amp_img_new_attrs');

function amp_img_new_attrs($attrs){

 $attrs['layout'] = 'fixed-height';
 unset($attrs['width']);
 
 return $attrs;
}

That’s all folks!

Note: It will work only with 0.9.86 or above version of AMPforWP.

Share
Published by
Marqas

How to create an AWeber form in AMP

If you want to add an AWeber form in AMP then first you need to…

3 years ago

How to setup webpushr notification in AMP

Webpushr is the fastest growing web push notifications platform that marketers love & developers rely…

3 years ago

How to add Adobe Analytics in AMP

Follow these steps to add Adobe Analytics in AMP Step 1: Go to WordPress Admin Area -> AMP…

4 years ago

What is the CWV plugin all about

Core Web Vitals are the subset of Web Vitals that apply to all web pages,…

4 years ago

How to fix “Alternate page with proper canonical tag” Page Index issue in Google Search Console

The following reasons can be shown for non-indexing. Server error (5xx) Your server returned a 500-level…

4 years ago

Google Analytics ( GA4 ) integration in AMPforWP

We have added the Google Analytics 4 ( GA 4 ) integration in AMPforWP v1.0.80.…

4 years ago