Community Forums › Forums › Archived Forums › General Discussion › Change the "read more" button text for certain categories only?
Tagged: read more
- This topic has 12 replies, 3 voices, and was last updated 6 years, 7 months ago by Paul.
-
AuthorPosts
-
August 29, 2017 at 1:27 am #210848PaulParticipant
Hi All,
Is there a way to change the "read more" button (text) in certain categories?
I am aware of how to change the "read more" button (text) in all results (pages, posts etc), but is there a way to change what is says (the text) for certain categories only?
If yes, could you also let me know where to put the code?
Thanks guys 🙂
August 29, 2017 at 2:58 am #210849Brad DaltonParticipantAugust 29, 2017 at 4:23 am #210851PaulParticipantThanks for your fast reply, appreciate that. Here is the code I currently have, I'm not quite sure where to edit it, are you able to help to the point where I can just change the category id numbers?
/** Customize Read More Text */
add_filter( 'excerpt_more', 'child_read_more_link' );
add_filter( 'get_the_content_more_link', 'child_read_more_link' );
add_filter( 'the_content_more_link', 'child_read_more_link' );
function child_read_more_link() {return 'VIEW FULL PROFILE';
}August 29, 2017 at 4:33 am #210852Brad DaltonParticipantYou need to add the conditional tag. If you look at the page i linked to, it includes example with conditional tags so you can learn where to put the conditional.
August 29, 2017 at 4:39 am #210853PaulParticipantThanks, I did have a look but I'm not sure where to add the conditional tag to the above code 🙁
August 29, 2017 at 6:56 am #210858ErikaParticipantHi Paul,
Here is code that already has the snippets Brad suggested inserted. Simply replace the bold text with your own.
//* Modify read more link
add_filter( 'get_the_content_more_link', 'THEMENAME_read_more_link' );
function THEMENAME_read_more_link() {
if ( is_category( 'Stinky Cheeses' ) ) {
return '... Text Here »';
}
if ( is_category( 'Stinky Cheeses' ) ) {
return '... Text Here »';
}
}August 29, 2017 at 6:57 am #210859ErikaParticipantAnd also edit the "Text Here" text that became a link 🙂 Copy and paste each "if" section entirely for more variances if needed.
August 29, 2017 at 7:18 am #210864Brad DaltonParticipantThis works however you will need to change the category slug in the code https://wpsites.net/web-design/change-read-more-text-conditionally/
August 29, 2017 at 7:47 pm #210893PaulParticipantThanks Erika, that looked pretty straight forward until Brad added his extra comment. With this in mind, should the code still look like your code above Erika? Or should more be added?
Apologies Brad, I am struggling with your directions, but I am grateful for your offers of help.
I just need the entire code all in one paste please if possible?
August 29, 2017 at 8:16 pm #210894ErikaParticipantPaul,
Go ahead and try my code as is, making the adjustments I recommended. I tested the code on one of my sites and it works.
August 31, 2017 at 5:25 pm #210997PaulParticipantHi Erika,
Thanks again for your help. I just have a few more questions if that's okay?
- Where do I copy the code? (I put it in my functions.php but it crashed the site, I had to FTP upload a previous version of the file to get the site up again).
- Does the code need to sit in a particular place within the file?
- I am using the genesis child theme "Metro Pro Theme", do I need to change the THEMENAME to the child theme "Metro Pro Theme", or the genesis theme?
- If it is the Metro Pro Theme, do I change the text like this? Metro Pro Theme, OR like this, Metro-Pro-Theme, OR like this Metro_Pro_Theme?
Sorry for all the questions and I appreciate your help 🙂
Paul.
August 31, 2017 at 5:43 pm #210998ErikaParticipantPaul,
I think I know why your site crashed. If you contact me through my site listed below, I can send you the code. Part of the code is a link, and this forum converts it into the blue "Text Here" seen above. You need the link part of it to make the code work and not crash the site.
August 31, 2017 at 6:41 pm #211006PaulParticipantThis reply has been marked as private. -
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.