In this example I’m talking about how to display a specific company slogan in a certain color. This slogan is found in the header and content.
Of course my client doesn’t want to put in span class="foo"
every time. This is what it should look like:
Therefor I have to write a function. First I have to search for the string “by *FOO” and wrap a span around “by” as well as around “*FOO”, since it is also displayed without “by”. If I added it to the first function “*FOO” which already has a span would get an additional span. Here is the code:
function colorize_FOO($content) {
$str = "*FOO";
$newstr = "*FOO";
$html = str_replace($str, $newstr, $content);
return $html;
}
function colorize_by($content) {
$str = "by *FOO";
$newstr = "by *FOO";
$html = str_replace($str, $newstr, $content);
return $html;
}
add_filter('the_title', 'colorize_by',1);
add_filter('the_content', 'colorize_by',1);
add_filter('the_title', 'colorize_FOO',1);
add_filter('the_content', 'colorize_FOO',1);
Sure there are more elegant methods, but a better one didn’t come in my mind so quickly 😉
Comments
4 responses to “How To Highlight A Slogan In WordPress”
If you first think in German and then write it down in English, it’ll be very ugly text…
Hi Michael,
dumb question from a only-copy-paste-coder: What php-file of a theme-template would be the right one for this code and at what place (order before after section x)??
A hint would be great!
Thanky in advance,
Pete
Hi Pete,
copy the code in the functions.php of your theme. No special place is needed.
How To Highlight A Slogan In WordPress…
In this example I’m talking about how to display a specific company slogan in a certain color. This slogan is found in the header and content….