WordPress.org

Ready to get started?Download WordPress

Forums

Adding a Span tag to page or post titles (1 post)

  1. kendawes
    Member
    Posted 2 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.