How to split up the_title and insert a span tag

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 “https://wordpress.stackexchange.com/” 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 “https://wordpress.stackexchange.com/”

EDIT:
Code removed & Pastebin created, this is my whole page for index.php: http://pastebin.com/0T9mt7Fu

3 Answers
3

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):

enter image description here


Then you can fetch your subtitle easily:

<?php
$sub_title=get_post_meta($post->ID,'subtitle',true);
if($sub_title != '') {
echo '<h1>'. the_title() .'<span>'. $sub_title .'</span></h1>';
} else {
echo '<h1>'. the_title() .'</h1>';
}
?>

.
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..:

<h1><?php the_title(); ?></h1>

Leave a Comment