Title: How to replace with from function.php?
Last modified: August 1, 2019

---

# How to replace with from function.php?

 *  Resolved [pilardcv1](https://wordpress.org/support/users/pilardcv1/)
 * (@pilardcv1)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/how-to-replace-with-from-function-php/)
 * Hi, I need to dynamically replace the  tag with the <amp-img> tag.
 * For example, replace this:
 * ![](imagen.png)
 * with:
 * <amp-img layout=”fixed” class=”fixed alignnone wp-image-5369 i-amphtml-element
   i-amphtml-layout-fixed i-amphtml-layout-size-defined i-amphtml-layout” src=”image.
   png” alt=”” width=”24″ height=”24″ i-amphtml-layout=”fixed” style=”width: 24px;
   height: 24px;”>  </amp-img>

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Rui Guerreiro](https://wordpress.org/support/users/takanakui/)
 * (@takanakui)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/how-to-replace-with-from-function-php/#post-11789971)
 * Hi [@pilardcv1](https://wordpress.org/support/users/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);
       ```
   
 *  Thread Starter [pilardcv1](https://wordpress.org/support/users/pilardcv1/)
 * (@pilardcv1)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/how-to-replace-with-from-function-php/#post-11789995)
 * 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?
 *  Plugin Author [Rui Guerreiro](https://wordpress.org/support/users/takanakui/)
 * (@takanakui)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/how-to-replace-with-from-function-php/#post-11790369)
 * 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.
 *  Thread Starter [pilardcv1](https://wordpress.org/support/users/pilardcv1/)
 * (@pilardcv1)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/how-to-replace-with-from-function-php/#post-11790509)
 * 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, 10 months ago by [pilardcv1](https://wordpress.org/support/users/pilardcv1/).
 *  Plugin Author [Rui Guerreiro](https://wordpress.org/support/users/takanakui/)
 * (@takanakui)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/how-to-replace-with-from-function-php/#post-11790556)
 * Use this modified version that already contains those filters.
 * [https://www.dropbox.com/s/lnbvnscp1fn76hc/menu-image.zip?dl=0](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;
       }
       ```
   
 *  Thread Starter [pilardcv1](https://wordpress.org/support/users/pilardcv1/)
 * (@pilardcv1)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/how-to-replace-with-from-function-php/#post-11793188)
 * 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>
 *  Plugin Author [Rui Guerreiro](https://wordpress.org/support/users/takanakui/)
 * (@takanakui)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/how-to-replace-with-from-function-php/#post-11793526)
 * 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.
 *  Plugin Author [Rui Guerreiro](https://wordpress.org/support/users/takanakui/)
 * (@takanakui)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/how-to-replace-with-from-function-php/#post-11823774)
 * Will close the topic for now.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘How to replace with from function.php?’ is closed to new replies.

 * ![](https://ps.w.org/menu-image/assets/icon-128x128.png?rev=2123398)
 * [Menu Image, Icons made easy](https://wordpress.org/plugins/menu-image/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/menu-image/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/menu-image/)
 * [Active Topics](https://wordpress.org/support/plugin/menu-image/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/menu-image/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/menu-image/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [Rui Guerreiro](https://wordpress.org/support/users/takanakui/)
 * Last activity: [6 years, 9 months ago](https://wordpress.org/support/topic/how-to-replace-with-from-function-php/#post-11823774)
 * Status: resolved