My titles, site wide, will follow this theme all within a h1 tag:
Main title heading / Sub-title text
I’m trying to wrap a span tag around all text after and including the ‘/’ so my markup will look like this:
<h1>Main title heading <span>/ Sub-title text</span></h1>
How do I accomplish this? I’m not great with PHP but I’ve tried playing with explode but can’t get the end result all I end up doing is hiding everything after the ‘/’
EDIT:
Code removed & Pastebin created, this is my whole page for index.php: http://pastebin.com/0T9mt7Fu
its best if you just use custom field type to create a sub title…
That way you leave the title un-touched and just add a field where
you can insert a value like so (calling field sub title):
Then you can fetch your subtitle easily:
.
i hope this a suitable solution for you… i use it on occasions
Cheers, Sagive
HOW TO:
Replace (i hope it looks the same in your theme) with the code above..:
This comes a bit late, but I donât know where else it would make sense. I had a similar problem and created a solution.
As toscho has pointed out, the_title is used in nav menus, too. He has created a filter to switch the title filter on/off for nav menusâwhich I personally think is Einsteinesque. (Thanks a bunch!)
So Iâve just modified his filter a little to make it work here. Then added the actual filtering function. Wherever you use space-pipe-space (” | “) in a post title field, the part after it gets wrapped up in a
<span>
tag (including the slash the original post author asked for).Hope it helps somebody!
I think the answer @Sagive SEO gave seems like the best approach from a semantic perspective. But if you prefer to keep both “titles” in the title field, a simple explode should work for you.
Try something like this:
ETA: following @toscho’s suggestion below, I added a couple lines to check the post type before filtering the title. This function should now only add the
<span>
‘s to the title on pages, not in nav menus, etc.