Title: php scripting help with widget_content
Last modified: August 20, 2016

---

# php scripting help with widget_content

 *  Resolved [chicagoave](https://wordpress.org/support/users/chicagoave/)
 * (@chicagoave)
 * [15 years ago](https://wordpress.org/support/topic/php-scripting-help-with-widget_content/)
 * Hello,
 * I am using widget logic both for conditionally displaying my widgets and also
   for the widget_content feature in working with ttftitles. Your example is great
   for replacing a single instance of content between the _**h2**_ tag in a widget
   but what if I want to replaces all instances where _**h2**_ or in my case _**
   a**_ appears? Looks like I would use preg_match_all or str_replace but I’m not
   good enough in php to write the code. After several trials and errors asking 
   if someone can help me out.
 * Here is what I’m working from, based on the provided example, but not sure how
   to correctly change preg_match to preg_match_all (?) or str_replace (?) or place
   the entire function inside a loop (?) to get a replace all going.
 * Thanks in advance!
 *     ```
       add_filter('widget_content', 'ttftext_widget_title');
   
       function ttftext_widget_title($content='')
   
       {   preg_match("/<a[^>]*>([^<]+)/",$content, $matches);
           $navitem=$matches[1];
           $insert_img=the_ttftext( $navitem, false, nav );
           $content=preg_replace("/(<a[^>]*>)[^<]+/","$1$insert_img",$content,1);
           return $content;
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [chicagoave](https://wordpress.org/support/users/chicagoave/)
 * (@chicagoave)
 * [15 years ago](https://wordpress.org/support/topic/php-scripting-help-with-widget_content/#post-2100465)
 * solved it with help from a friend. if anyone is interested.
 *     ```
       add_filter('widget_content', 'ttftext_widget_title');
   
       function ttftext_widget_title($content='')
   
       {   return preg_replace("/(<a[^>]*>)([^<]+)/e", "\"$1\".the_ttftext(\"$2\", false, nav)", $content);
       }
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘php scripting help with widget_content’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/widget-logic_c8dde5.svg)
 * [Widget Logic](https://wordpress.org/plugins/widget-logic/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/widget-logic/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/widget-logic/)
 * [Active Topics](https://wordpress.org/support/plugin/widget-logic/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/widget-logic/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/widget-logic/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [chicagoave](https://wordpress.org/support/users/chicagoave/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/php-scripting-help-with-widget_content/#post-2100465)
 * Status: resolved