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


  #1  
Old Aug 23, 2012, 01:36 PM
kdawes01's Avatar
kdawes01
 
102 posts · May 2009
Missoula, MT
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.
  #2  
Old Aug 23, 2012, 07:01 PM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
create a CSS insert
HTML Code:
.myred {color: red;}
edit the title so it is
HTML Code:
<span class="myred">First</span> word will be colored red
and you should see
First word will be colored red
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #3  
Old Aug 25, 2012, 12:12 PM
kdawes01's Avatar
kdawes01
 
102 posts · May 2009
Missoula, MT
Hi Juggledad,
Yes, that's true! And it works fine... Unless you have selected ATA's "Use Page/Post Options".
Atahualpa overides WordPress' the_title()tag with it's own functions and strips html tags from the title.

If using the WordPress drag 'n drop menu, ATA adds a span tag inside the page title link.

Ultimately, what I'm trying to do is be able to be able to put html in *only* the h1 titles used on pages and posts.

The above functions code that I pasted does what I want on pages/posts but messes up the d 'n d menu and I haven't checked but probably any other use of the title (widgets, etc.)

Do you know of a way to do what I want to do? My preference would be from the functions.php but I'm open to whatever works with using the ATA's "Use Page/Post Options" active.
__________________
Ken | The Web Mechanic
Many thanks to Flynn for the amazing Atahualpa. Please consider a donation!
  #4  
Old Aug 25, 2012, 07:35 PM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
just use '"' in place of the double quote like this
HTML Code:
<span class="myred">page</span> with a big title
NEVER MIND, it doesn't work as soon as you update it changes the value again.
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support

Last edited by juggledad; Aug 25, 2012 at 07:46 PM.
  #5  
Old Aug 28, 2012, 04:52 AM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
This should not be too difficult IF you are NOT using the Atahualpa Post options

The code for the page/post titles is in bfa_post_parts.php in teh function 'bfa_post_headline'
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #6  
Old Aug 28, 2012, 09:29 AM
kdawes01's Avatar
kdawes01
 
102 posts · May 2009
Missoula, MT
Absolutely JD!

It would have been a slam-dunk if my client wasn't insisting on my using the WordPress drag 'n drop menu function.


Slowly but surely I'm trying to work my way through Atahualpa 'title" coding usage to see if it can be done.

<sigh>
__________________
Ken | The Web Mechanic
Many thanks to Flynn for the amazing Atahualpa. Please consider a donation!
  #7  
Old Aug 28, 2012, 09:41 AM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
if they aren't using the Atahualpa page/post options (ato->Configure SEO->Use Post / Page Options?) then there are just 2 places in teh code that uses 'the_title()' - you could just put the code there. (lines 37 and 40 in version 3.7.7)
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #8  
Old Aug 28, 2012, 09:47 AM
kdawes01's Avatar
kdawes01
 
102 posts · May 2009
Missoula, MT
Sorry JD, I should have added that they *also* want the features provided by the ATA "use post/page options".

It may well be that they just don't get everything they want...

Ken
__________________
Ken | The Web Mechanic
Many thanks to Flynn for the amazing Atahualpa. Please consider a donation!
  #9  
Old Aug 28, 2012, 10:32 AM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
FYI I took a look at that code thinking about redesigning it and realized it was going to take a good two/three hours to recode it and test it for all cases. You have to take care of the case where
1) use the WP title with a link
2) use the WP title with NO link
3) a case where they don't enter a WP title (it is blank)
4) use the ata single post title
5) use the ata single post title as a link
6) the use the ata multi post title
7) the use the ata multi post title as a link

I think those are all the cases...this is why it is complex
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support

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


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