Community Forums › Forums › Archived Forums › Design Tips and Tricks › add text after post title
Tagged: titles
- This topic has 9 replies, 3 voices, and was last updated 9 years, 1 month ago by 3details.
-
AuthorPosts
-
February 15, 2015 at 4:08 am #1409003detailsMember
Hi, I have a Sold category which I would like to show the word "Sold" in a different colour after all the titles in that category sitewide...
this is what I have so far, but is doesn't work....add_filter( 'the_title', 'text_after_title_change_color' ); function text_after_title_change_color( $title ) { global $post; if (in_category('11') { if ( $title == $post->post_title ) { return $title . '<span class="after-title">Sold</span>'; } } else { if ( $title == $post->post_title ) { return $title . ''; } }
any ideas on what am I doing wrong please?
http://3details.comFebruary 15, 2015 at 6:11 am #140901Brad DaltonParticipantFebruary 15, 2015 at 6:26 am #1409043detailsMemberthanks for looking but I just solved it!:
add_filter( 'the_title', 'text_after_title_change_color' ); function text_after_title_change_color( $title ) { global $post; if ( $title == $post->post_title && in_category('11')) { return $title . '<span class="after-title">Sold</span>'; } else { return $title . '<span class="after-title"></span>'; } }
February 15, 2015 at 7:17 am #1409153detailsMembererrr maybe I spoke to soon....
This code works in my custom_functions.php however, it even applies the text on the end of post titles in the backed admin area
Worse, it reverts to raw html, e.g. "post name <span class="after-title"> - Sold</span>"I would prefer to limit the output to archive views and single post views....
February 15, 2015 at 7:47 am #140918Brad DaltonParticipantFebruary 15, 2015 at 8:26 am #1409203detailsMemberI can't seem to find the page but its a variation on your code no? WPsites?
I'm still looking....February 15, 2015 at 8:33 am #140921Genesis DeveloperMembercan you replace
in_category('11')
byis_category(11)
and then test the site again?
February 15, 2015 at 9:07 am #1409273detailsMemberThanks Genesis Developer, I tried this but it has not changed things
this is the current state of the code in my custom_functions.php:add_filter( 'the_title', 'text_after_title_change_color' ); function text_after_title_change_color( $title ) { global $post; if ( $post->post_title && in_category('11')) { return $title . '<span class="after-title"> - Sold</span>'; } else { return $title . ''; } }
I changed
if ( $title == $post->post_title && in_category('11')) {
toif ( $post->post_title && in_category('11')) {
because some posts in category 11 were not adding the Sold text to their titlesStill have the same problem on the backend with raw html on the post titles
February 15, 2015 at 12:29 pm #140944Brad DaltonParticipantYou might want to respect my copyright policy first as well as the forum rules regarding copyright of other peoples work.
February 16, 2015 at 6:58 am #1410123detailsMemberBrad, I said “I think” its your code because through searching I saw that your site has very similar examples (there is no author or copyright comment in my snippet…) Unless you can provide the url (which I can’t find) then I’m assuming I picked it up elsewhere, can you do that, just to clarify your accusation please?
many thanks,
Peter -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.