Add line break in PHP for Wordpress Post title containing " | "

Hello there,

I have a situation I’d like to fix with our Wordpress template. If you look here: http://www.slarc.com/projects/ Some of the project titles are getting cut off because there are only a certain number of characters allowed per title. But for every title we have " | " between the project title and the project location. Is there a way in our PHP coding that we can tell it to replace " | " with a linebreak, so the location of the projects is always on a line below the title?

I don’t know where to start with this coding if I can get some help, it would be much appreciated!

Thanks,
Lorne

http://php.net/manual/en/function.str-replace.php


$new_title = str_replace(" | ", "</br>", $title);

Thanks for the quick reply Wolfe.

I added your code to my line of PHP in my template:

<h3><a href="<?php the_permalink(); ?>"><?php $title = the_title('','',FALSE); echo substr($title, 0, 40), $newtitle = str_replace(" | ", "</br>", $title);?></a></h3>

However if you look at the page: http://www.slarc.com/projects/ You’ll see it’s still adding the title with the location, then duplicating the title, and adding the break to another line for the location. I’ve tried different variations of the code, but can’t seem to get it to work.

Why is it duplicating the title? (sorry for the rookie questions, I’m not very familiar with PHP).

Thanks,
Lorne

I finally got it!

I needed to remove “$title” from the echo substr.

For reference this is working with:


<h3><a href="<?php the_permalink(); ?>"><?php $title = the_title('','',FALSE); echo substr('', 0, 40), $newtitle = str_replace(" | ", "</br>", $title);?></a></h3>