Hi @pilardcv1
Try using str_replace inside the menu-image.php around line 534
Replace this line
$none = ''; // Sugar.
by these 2 lines
$none = ''; // Sugar.
$image = str_replace('<img', '<amp-img', $image);
Thanks for the reply.
But, I need to modify it from the “function.php” file of my custom theme, so it doesn’t get lost with the plugin update.
It’s possible?
I can add a filter in the next update so you can do it in the functions.php of the child theme. But for now, you will have to replace it directly in the plugin.
Excellent! Thank you! I look forward to the update.
One last comment. Doing this:
Try using str_replace inside the menu-image.php around line 534
Replace this line
$ none = ”; // Sugar
by these 2 lines
$ none = ”; // Sugar
$ image = str_replace (‘<img’, ‘<amp-img’, $ image);
I get:
<li>
<a href="">
<amp-img width="24" height="24" src="images.png">
<img width="24" height="24" src="image.png" />
<span class="menu-image-title">Title</span>
</amp-img>
</a>
</li>
Instead of:
<li>
<a href="">
<amp-img width="24" height="24" src="images.png">
<img width="24" height="24" src="image.png" />
</amp-img>
<span class="menu-image-title">Title</span>
</a>
</li>
The title is within <amp-img>.
-
This reply was modified 6 years, 9 months ago by
pilardcv1.
Use this modified version that already contains those filters.
https://www.dropbox.com/s/lnbvnscp1fn76hc/menu-image.zip?dl=0
The problem can be in the str_replace, I didn’t test that intensively. Check other ways to replace the tags.
Use the code below inside the functions.php of your child themes to use the filter
add_filter('menu_image_img_html', 'replace_menu_item_img_html');
function replace_menu_item_img_html( $image ){
$image = str_replace('<img', '<amp-img', $image);
return $image;
}
I used the modified version of the plugin and the filter code in the function.php of my theme and it doesn’t work. The
tag is not replaced with <amp-img>
Check if the pasted code doesn’t have any incorrect format, especially the single quotes. That can happen in the copy/paste process.
It was working in my tests, well the HTML was being changed but the results of the preg_replace weren’t accurate.
Will close the topic for now.