0

Alright I am starting a music blog and I am working hard at coding up this theme but I am wondering why I can't do this successfully within WordPress when I know for sure it's possible.

Alright so let's say that the first half of the title is the artist name and it's code looks something like what's shown below.

<b>Example Song Artist  - </b>

After the - is what would start the song title and that would be in a different tag the <strong> tag would be used for that but... within css we have it set so that it's suppose to look like this.

b {
color: black;
}
strong {
color: red;
}

above we state that we want the colors to be changed within those tags, how ever when I try and do this in wordpress with the <?php the_title(); ?> function it does not let me print the title in this format? Is there some way that I can create something within the upload panel which will allow me to do this?

Finished idea of how I want it to look for each title. enter image description here

2 Answers 2

0

Without all the info of what is actually happening I'm assuming that the title is output with the Song Artist and the Song Name together. But like you said with a dash in the middle.

With that assumption, then you can accomplish this with a custom function that filters the_title before it's output.

Try putting this in your functions.php file:

function my_title_filter( $title ) {
  // only filter if in the loop and is home page. Edit these accordingly.
  if ( in_the_loop() && is_home() ) { 

    $split_title = explode( ' &#8211; ', $title ); // this will split the title into 2 parts. part one before the ' - ' and part 2 after the dash
    // now create the title output format you want
    $new_title = '<b>' . $split_title[0] . ' - <strong>' . $split_title[1] . '</strong></b>';

    return $new_title;
  }
  // if not in the loop or home page, then return regular title
  return $title;
}
add_filter( 'the_title', 'my_title_filter', 10, 2 );

Then from there that should format the title like you want... ie.

<b>Song Artist - <strong>Song Name</strong></b>

Although I don't quite agree with putting a 'strong' inside a 'b' you can do whatever you want. Personally I'd change the 'b' to a 'strong' wrapped around the title and then wrap the Song Name in a 'span' with a CSS class, and work from there.

0

You have to put song title into <span> tag and

.classOfContainer span{color:red;}

Not the answer you're looking for? Browse other questions tagged or ask your own question.