Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. function link_words( $text ){
  2. //array of words and links
  3. $words_to_replace = array(
  4. 'guanciale' => '<a href="#">guanciale</a>',
  5. 'lattuga' => '<a href="#">lattuga</a>'
  6. );
  7. foreach ($words_to_replace as $old_word => $new_word){
  8. $reg =sprintf('/<a [^>]+>([^<]+)+[%s]+<\/a>/',$old_word);
  9. if(!preg_match_all($reg, $text)){
  10. $text = preg_replace("/$old_word/", $new_word, $text, 1);
  11. echo '<h1>Ho messo il link</h1>';
  12. }
  13.  
  14. return $text;
  15. }
  16. add_filter( 'the_content', 'link_words' );
  17. add_filter( 'the_excerpt', 'link_words' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement