Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme » Center area post/pages »

Span tag in page/post title - Customizing page/post title


 
Prev Previous Post   Next Post Next
  #1  
Old Aug 23, 2012, 01:36 PM
kdawes01's Avatar
kdawes01
 
102 posts · May 2009
Missoula, MT
Span tag in page/post title - Customizing page/post title

This shows up from time to time and I now have a client who wants the first word of his page titles formatted differently from the remainder of the title..

I actually have come across something that was posted on wordpress.org that looks like it would work, actually it does, just too well!

From the post...

...for just the page title, edit page.php and replace the_title(); with:

Code:
$words = explode(' ', the_title('', '',  false));
$words[0] = '<span>'.$words[0].'</span>';
$title = implode(' ', $words);
echo $title;
----
or for generally all titles (this will add the span around the first word in any title, such as post titles, page titles, and the_title is also used for instance in page lists) -
add something like this to functions.php of your theme:
Code:
add_filter('the_title', 'span_first_word');
function span_first_word($title) {$words = explode(' ', $title);
$words[0] = '<span>'.$words[0].'</span>';
$title = implode(' ', $words);
return $title;
}
For a number of reasons, I prefer the function method - Primarily because I often add things to the Atahualpa functions.php and when ATA updates, I just have to remember to make one modification to one file.
It's pretty much no muss no fuss.
The "add filter" works like a charm for what I want, but of course it messes up any other usage of "the_title();", including the WordPress drag and drop menu.

And of course, my client insists on the WP menu.


So my question is - Is there a way to wrap the function so that it will only be active in a post or page and not other places that "the_title();" is used?

If not, I'll probably just have to go with the first method and figure out where to modify the template, as much as I'd rather not.

Any thoughts?
__________________
Ken | The Web Mechanic
Many thanks to Flynn for the amazing Atahualpa. Please consider a donation!

Last edited by kdawes01; Aug 23, 2012 at 01:46 PM.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
add page/post title to header site title. aehageman Header configuration & styling 6 Oct 21, 2011 04:16 AM
[SOLVED] Span Tag in Post Title screwing with Display in Excerpt Title vCopia Excerpts, Read more, Pagination 21 Sep 30, 2011 06:17 AM
Show Post Title as Page Title patgeary Header configuration & styling 2 Mar 27, 2009 07:10 PM
Change color of post title only, not page title jockoe Atahualpa 3 Wordpress theme 1 Feb 26, 2009 06:14 PM


All times are GMT -6. The time now is 11:10 AM.


Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.