Support » Plugins » Adding a Span tag to page or post titles

  • I came across a nifty piece of code in the forums that wraps a span tag around the first word of a title. Good for, say differently sized or colored words in a page title.

    Unfortunately, it wraps it around all title instances – like the menu (which I don’t want)

    Is there a way to restrict the function to only page and post titles?

    Here’s the code…

    // add span tag to title first word
    add_filter('the_title', 'span_first_word');
    function span_first_word($title) {
    $words = explode(' ', $title);
    $words[0] = '<span>'.$words[0].'</span>';
    $title = implode(' ', $words);
    return $title;

    Thanks for any input!

  • The topic ‘Adding a Span tag to page or post titles’ is closed to new replies.