Support » Theme: GeneratePress » Change Read more text in one category

  • Resolved FeliceAntonio

    (@antonio_09)


    Hi there,
    I wonder why this code found here does not work into my functions.php child theme.
    I tried to change in:

    add_filter( 'generate_excerpt_more_output', function( $more ) {
        if ( in_category( 'NUMBER_CATEGORY' ) ) {
            return sprintf( '<a class="read-more" title="%1$s" href="%2$s">%3$s</a>',
                the_title_attribute( 'echo=0' ),
                esc_url( get_permalink( get_the_ID() ) ),
                __( 'Read more', 'generatepress' )
            );
    	}
        return $more;
    }, 50 );

    But does not work.
    Thanks.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 16 through 22 (of 22 total)
  • Hi Felice,

    You can try this.

    add_filter( 'generate_excerpt_more_output',function($output){
    if(in_category(1)){ 
    	return sprintf( '<p class="read-more-container"><a title="%1$s" href="%2$s">%3$s</a></p>',
            the_title_attribute( 'echo=0' ),
            esc_url( get_permalink( get_the_ID() ) . apply_filters( 'generate_more_jump','#more-' . get_the_ID() ) ),
    		'YOUR NEW TEXT HERE'
        );
    } else {
     	return $output;
    }
    });

    I’ve already tested this on my sandbox site. We basically just used Tom’s code, we just changed the condition from is_category() to in_category().

    Change the value inside in_category() with the category ID or slug you want the read more link changed. Change the 'YOUR NEW TEXT HERE' line to the text you want to display.

    • This reply was modified 7 months, 3 weeks ago by ejcabquina.
    Thread Starter FeliceAntonio

    (@antonio_09)

    Is unbelievable! In the past, I solved a more complex issue, and now, for a change that seems simple, I can’t get.
    I tried several conditions tags: is_category (the most logical because I need to change text just in the archive category page) in_category and has_category.
    I wonder why.

    That’s strange.

    With the same code I’ve provided, I was able to make it work.

    Here’s a link to my sandbox site. http://c9294e7fd30e.ngrok.io/

    Perhaps there’s an issue with the category you’re adding? Can you try adding the slug instead? Ex: if(in_category('your-category-slug')){...

    • This reply was modified 7 months, 3 weeks ago by ejcabquina.
    • This reply was modified 7 months, 3 weeks ago by ejcabquina.
    Thread Starter FeliceAntonio

    (@antonio_09)

    Sure strange.
    I don’t see the link you posted but I don’t have doubt in your sandbox goes well.
    I controlled again my functions.php and I don’t see problems, or conflict, otherwise crash the website.
    I’m sorry for the trouble!

    I don’t see the link you posted but I don’t have doubt in your sandbox goes well.
    I controlled again my functions.php and I don’t see problems, or conflict, otherwise crash the website.

    As we’re no idea how many plugins or snippets is added to your functions.php, its really difficult to know what’s causing the code to not work.

    I recommend having a staging site where you add things one by one so you can find which is causing problems.

    I’m sorry for the trouble!

    No problem.

    Thread Starter FeliceAntonio

    (@antonio_09)

    Hi there,
    not all evil leads to harm!!!
    I’m searching to simplify as most as possible my website, so I decided to remove Read More:

    function generate_content_more() {
        return '';
    }
    add_filter( 'the_content_more_link', 'generate_content_more' );

    However I think is right close this ticket as solved, because your code is right, and goes well, regardless of possible conflict in the code of my functions.php file.
    Thanks again for your time, and your availability -:)

    No problem. 🙂

Viewing 7 replies - 16 through 22 (of 22 total)
  • The topic ‘Change Read more text in one category’ is closed to new replies.