Site logo

[Support request] Child Theme – removing GP excerpt and replacing with custom from functions.php

Home Forums Support [Support request] Child Theme – removing GP excerpt and replacing with custom from functions.php

Home Forums Support Child Theme – removing GP excerpt and replacing with custom from functions.php

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2495729
    Charles

    Hello, I am converting a custom site from another theme. Ther is a block of code in functions.php that I can not get to work, It creates a custom button for the read more excerpt.

    
      add_filter( 'excerpt_more', 'cct_excerpt_more' );
      function cct_excerpt_more( $more ) {
        global $post;
        return '<p><a href="'. get_permalink( $post->ID ) .'" class="excerpt-more">Keep reading..</a>';
      }
    

    This was wrapped in a child_theme_setup function along with a bunch of other code

    add_action('genesis_setup','child_theme_setup', 15);
    function child_theme_setup() {

    From what I understand from the WP docs, I need to remove the parent themes excerpts, but I can not find them in the GP parent theme to match and remove. Can you help point me in the right direction here?

    WP Documentation for it: (link):

    The key is to put your remove_filter() code in a function that executes from an action hook that triggers after the parent theme is loaded. The following code is an example of the additional code needed to get the above code to work from a child theme of the parent theme Twenty Eleven. You will need to examine your actual parent theme’s code for the correct parameters in the remove_filter() code, they must exactly match the add_filter() parameters used by the parent.

    function child_theme_setup() {
    	// override parent theme's 'more' text for excerpts
    	remove_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' ); 
    	remove_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );
    }
    add_action( 'after_setup_theme', 'child_theme_setup' );

    Also, I noticed that in the old theme build using Genesis a lot of the stuff in functions.php such as custom meta data, enquing CSS /scripts, removing rsd links, query strings, etc were wrapped in the child_theme_setup function. I am currently not doing that with my GeneratePress child functions.php, should I also add those things into a child_theme_setup function not straight into functions.php?

    Thank you

    #2496028
    David
    Staff
    Customer Support

    Hi there,

    to cover the last thing first:

    should I also add those things into a child_theme_setup function not straight into functions.php?

    No, GeneratePress handles that, so you can just add your functions directly into the child theme functions.php

    The read more link, are the posts using a Read More tag for their excerpts ?
    If so – see here for the necessary function:

    https://docs.generatepress.com/article/generate_content_more_link_output/

    If its the auto excerpt, then see here:

    https://docs.generatepress.com/article/generate_excerpt_more_output/

    Let me know if i understood correctly.

    #2506377
    Charles

    Thank you.

    The generate_excerpt_more_output worked perfectly.

    https://github.com/tomusborne/generatepress/blob/3.0.2/inc/structure/post-meta.php#L452-L462

    #2506968
    David
    Staff
    Customer Support

    Glad to hear that!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.