• I would like to have the two words in my site titles in different colours – any guidance would be much appreciated!

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • AddWeb Solution

    (@addweb-solution-pvt-ltd)

    Hello @declanmaherry,

    First off all add below code into your function.php which is in Appearance >Editor > function.php (In right).

    /**
    * Add the <span>...</span> tag to the first word of the blog title.
    */
    
    add_filter( 'body_class', function( $class ){
    	add_filter( 'bloginfo', 'change_first_word_color', 10, 2 );
    	return $class;
    });
    
    function change_first_word_color( $output, $show ){
    	static $count = 0;
    
    	//This will target the "name" part.:
    
    	if( 'name' === $show ) {
    	// Target the second representative:
    		if( 2 === ++$count ){
    			remove_filter( current_filter(), _FUNCTION_ );
    
    			// Change the color of first word.:
    			$first_title = explode( ' ', $output );
    			if( count( $first_title ) > 0 ){
    				$first_title[0] = sprintf( '<span>%s</span>', $first_title[0] );
    			}
    			$output = join( ' ', $first_title ); 
    		}
    	}
    	return $output;
    }

    And add this CSS into your stylesheet of the currently active theme.

    h1.site-title span{
      color: #000; /*add your dresire color here.*/
    }

    Hope this will helps you.
    Thanks.

    Thread Starter declanmaherry

    (@declanmaherry)

    Thank you so much!

    I am a little confused about two things though;

    1. Which parts of the code do I need to populate with the actual text – if any? (eg. $first_title = $ISO (the first word in the title))

    2. Do i need to paste the code into a specific place within the function and style sheets? There are several sections dealing with the title.

    Thanks in advance
    Declan

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Two different colors in title text’ is closed to new replies.