• Say I have a site for a company called BrandMaster and they want to have the second word in their brand name to always be italicized. Can I write something in my function.php to do this automatically?

    With my rather meager PHP skills I was able to pull this off:

    // Italicize Brandmaster
    add_filter('the_content', 'brandmaster', 99);
    function brandmaster( $content )
    {
        return str_replace('Brandmaster', 'Brand<i>Master</i>', $content);
    }

    This works but only for the_content. How can I extend this to sidebar content, titles etc.?

Viewing 3 replies - 1 through 3 (of 3 total)
  • To add it for different areas you’ll need to add additional actions for each area that you want it to show in.

    I know that titles can be done with the the_title action, like content, but I’n not sure of what would be needed for sidebar text… that could be dependant on what widgets you use, so you might need to check the code of each widget to see what filters are available.

    Dion

    (@diondesigns)

    Another option is to add:

    ob_start();

    to the top of the theme’s header.php file, and at the bottom of the theme’s footer.php file, add:

    echo str_replace('Brandmaster', 'Brand<i>Master</i>', ob_get_clean());

    This has the advantage of working globally, but it could cause problems if “Brandmaster” is used in an attribute such as a title or class. Since your original code would have the same problem and you didn’t mention such a problem, maybe it’s worth giving this a try.

    Thread Starter betadog

    (@betadog)

    Thanks to both of you. I was able to replace titles as well with catacaustic’s addition. But DionDesigns’s method takes care of my whole site the way I needed it. Thank you again!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Italicize a certain word across the whole site’ is closed to new replies.