Advertisement
BakerMan

Additional Fields to Linked URLs (TEC 2.0.11)

Jan 21st, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 KB | None | 0 0
  1. function linkURLsInCustomFields($html) {
  2.     $matches = array();
  3.     $pattern = '#<dd.*>(https?:\\/\\/[a-zA-Z0-9-\\.]+\\.[a-zA-Z0-9-\\.]+)<\/dd>#';
  4.  
  5.     preg_match_all($pattern, $html, $matches);
  6.     $matches = $matches[1];
  7.     $totalMatches = count($matches);
  8.  
  9.     if ($totalMatches >= 1) {
  10.         for ($i = 0; $i <= $totalMatches; $i++) {
  11.             $match = $matches[$i];
  12.             $link = '<a href="'.$match.'">'.$match.'</a>';
  13.             $html = str_replace($match, $link, $html);
  14.         }
  15.     }
  16.  
  17.     return $html;
  18. }
  19.  
  20. add_filter('tribe_the_custom_fields', 'linkURLsInCustomFields');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement