Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function link_words( $text ){
- //regular expression to verify if text contains tag a
- //array of words and links
- $words_to_replace = array(
- 'guanciale' => '<a href="#">guanciale</a>',
- 'lattuga' => '<a href="#">lattuga</a>'
- );
- foreach ($words_to_replace as $old_word => $new_word)
- {
- $reg =sprintf('/<a [^>]+>([^<]+)+[%s]+<\/a>/',$old_word);
- if(!preg_match_all($reg, $text)){
- $text = preg_replace("/$old_word/", $new_word, $text, 1);
- echo '<h1>Ho messo il link</h1>';
- }
- return $text;
- }
- add_filter( 'the_content', 'link_words' );
- add_filter( 'the_excerpt', 'link_words' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement