WordPress.org

Ready to get started?Download WordPress

Forums

Theme Hocks (2 posts)

  1. Danny159
    Member
    Posted 1 year ago #

    Hey,

    I have the following code in my theme functions.php file...

    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;
    }

    What that does is adds <span> around the first word of the title...

    However it adds <span> in the admin list too... but displays the word..
    EG: <span>About</span> Us

    Is there a way to only add <span> if its been displayed on the front of the website?

    Dan

  2. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

    What is the purpose of adding the span tags? If you want to add style to that word, you can almost certainly do it using CSS with the existing tags or classes or ID's. Can you post a link to your site and be more specific about what you are trying to do?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.