add_filter sometimes working, sometimes not working … simply replacing text
-
I’ve asked a similar question quite a while ago and didn’t get any helpful responses.
I’m trying to replace specific contain across my entire website.
/** * Replace content */ add_filter('the_content', 'wr_replace_text', 100); add_filter('the_excerpt', 'wr_replace_text', 100); add_filter('the_title', 'wr_replace_text', 100); add_filter('category_description', 'wr_replace_text', 100); add_filter('term_description', 'wr_replace_text', 100); add_filter('pre_user_description', 'wr_replace_text', 100); function wr_replace_text($text){ $replace = array( '[myname]' => '<span class="name">MyName</span>', '?' => '<span class="para">?</span>', '...' => '…', '(c)' => '?', '?' => '?', '?' => '?', '?' => '?', '“' => '?', ' - ' => ' — ', ' – ' => ' — ', ' –,' => ' —, ', ); $text = str_replace(array_keys($replace), $replace, $text); return $text; }
The snippet above is all I’m working with. This seems to work quite randomly. E.g. the replacement of
[myname]
works almost everywhere.However the replacement of the quotes doesn’t always work. There are posts, or pages where there are
"
transformed to?
and there are others where it randomly doesn’t happen.In example: As mentioned above
[myname]
works almost everywhere, except for my search-results. Even though my search-results usethe_excerpt()
to display a teaser-text of the result the[myname]
slug doesn’t get replaced in there. However for normal blog-teasers on my front-page where I also usethe_excerpt()
it does work.Why could there be such an unconsitancy? Any ideas on that?
Thank you in advance.
Matt
- The topic ‘add_filter sometimes working, sometimes not working … simply replacing text’ is closed to new replies.