Home › Forums › Support › Child Theme – removing GP excerpt and replacing with custom from functions.php
- This topic has 3 replies, 2 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
January 14, 2023 at 1:19 pm #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
January 15, 2023 at 3:33 am #2496028David
StaffCustomer SupportHi 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.
January 23, 2023 at 1:43 pm #2506377Charles
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
January 24, 2023 at 4:50 am #2506968David
StaffCustomer SupportGlad to hear that!
-
AuthorPosts
- You must be logged in to reply to this topic.