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.

Of course my client doesn’t want to put in span class="foo" every time. This is what it should look like:

highligt a slogan in WordPress

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 😉


Posted

in

by

Comments

4 responses to “How To Highlight A Slogan In WordPress”

  1. Pascal Avatar

    If you first think in German and then write it down in English, it’ll be very ugly text…

  2. Pete Avatar
    Pete

    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

  3. Michael Avatar

    Hi Pete,
    copy the code in the functions.php of your theme. No special place is needed.

  4. 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….