Sridhar published a new post on his blog yesterday on how to change the content limit on a post archive page using Genesis. This was a great post and jogged my memory that I needed to do something similar. My situation was that I needed to REMOVE the content from a custom post type’s archive. To get this to work, some code had to be reworked. Here’s the code I came up with to remove the excerpt/content from a custom post type archive page.
Before
After
<?php //* Mind this opening php tag | |
/** | |
* EngageWP.com | |
* Remove content excerpt from custom post type archive in Genesis | |
*/ | |
//* Grab the content for each custom post type | |
add_action( 'genesis_before_loop', 'rv_cpt_excerpts' ); | |
function rv_cpt_excerpts() { | |
// Set the custom post types to check | |
$post_types = array( 'product' ); | |
// If the archive is an archive of one of those custom post types | |
if ( is_post_type_archive( $post_types ) ) { | |
add_filter( 'genesis_pre_get_option_content_archive_limit', 'rv_downloads_excerpt_length' ); | |
} | |
} | |
// Set content limit to 1 character (setting it to 0 displays the entire post) | |
function rv_downloads_excerpt_length() { | |
return '1'; | |
} | |
//* Modify the read more link to remove the "..." | |
add_filter( 'get_the_content_more_link', 'rv_read_more_link' ); | |
function rv_read_more_link() { | |
if ( is_post_type_archive( 'product' ) ) { | |
return '<a class="more-link" href="' . get_permalink() . '">View Product</a>'; | |
} | |
} |
This code goes in your functions.php or a custom plugin.
Can you please post before and after screenshots?
Hey, Sridhar. I updated the post to include Before-and-After’s.
We can simply do this, right?
https://gist.github.com/srikat/6e9f458534c726c67630
I tried a couple things that would seem easier but the results were odd. I tried your snippet exactly and it didn’t work for me (the content was only removed from one of the posts). Have you tested it?
I’ve updated the hook name. Please refresh the snippet page and try again.
Still no luck. That snippet didn’t change anything from the default.
Check http://websitesetuppro.com/demos/devsite/books/ (a CPT archive page with content removed using my suggested snippet) vs a standard category archive page, http://websitesetuppro.com/demos/devsite/category/uncategorized/