Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Center area post/pages (http://forum.bytesforall.com/forumdisplay.php?f=32)
-   -   Span tag in page/post title - Customizing page/post title (http://forum.bytesforall.com/showthread.php?t=18239)

kdawes01 Aug 23, 2012 01:36 PM

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?

juggledad Aug 23, 2012 07:01 PM

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

kdawes01 Aug 25, 2012 12:12 PM

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.

juggledad Aug 25, 2012 07:35 PM

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.

juggledad Aug 28, 2012 04:52 AM

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'

kdawes01 Aug 28, 2012 09:29 AM

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>

juggledad Aug 28, 2012 09:41 AM

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)

kdawes01 Aug 28, 2012 09:47 AM

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

juggledad Aug 28, 2012 10:32 AM

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


All times are GMT -6. The time now is 02:26 AM.

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