Filters for what shows on the blog and archive pages — excerpt length, the read more link, and featured images. Most of these are set in Blog; see the Blog Content and Featured images sections.
Jump to
- Excerpts and read more
- Featured images
- Blog layout (GP Premium)
Excerpts and read more
excerpt_length
GP Premium — Blog module.
The excerpt_length filter (a WordPress core filter) sets the number of words in the excerpt; GeneratePress hooks into it only while the Blog module is active.
Parameters: $length (int, number of words). Default: the Blog module’s Excerpt Length setting. Without the Blog module active, WordPress’s own default of 55 applies, unfiltered by GeneratePress.
add_filter( 'excerpt_length', 'lh_custom_category_excerpt_length', 1000 );
function lh_custom_category_excerpt_length( $length ) {
if ( is_category() ) {
return 0;
}
return $length;
}
Related: generate_show_excerpt Guide: Blog — Blog Content
generate_show_excerpt
GP Free
The generate_show_excerpt filter chooses whether a post shows its excerpt or the full content on the blog and archive pages.
Parameters: $show_excerpt (boolean). Default: your Blog Content setting (Customize → Blog → Blog Content); always true on search results, and always false when the post uses the more tag or isn’t the standard post format.
add_filter( 'generate_show_excerpt', 'tu_full_post_search' );
function tu_full_post_search( $show_excerpt ) {
if ( is_search() ) {
return false;
}
return $show_excerpt;
}
Related: excerpt_length Guide: Blog — Blog Content
generate_excerpt_more_output
GP Free
The generate_excerpt_more_output filter changes the HTML markup of the “Read more” link inside excerpts.
Parameters: $output (string, HTML). Default:
sprintf(
' ... <a title="%1$s" class="read-more" href="%2$s" aria-label="%4$s">%3$s</a>',
the_title_attribute( 'echo=0' ),
esc_url( get_permalink( get_the_ID() ) ),
__( 'Read more', 'generatepress' ),
sprintf(
/* translators: Aria-label describing the read more button */
_x( 'More on %s', 'more on post title', 'generatepress' ),
the_title_attribute( 'echo=0' )
)
)
add_filter( 'generate_excerpt_more_output', function( $output ) {
return str_replace( 'class="read-more"', 'class="read-more MY-CUSTOM-CLASS"', $output );
} );
Related: generate_content_more_link_output Guide: Blog
generate_content_more_link_output
GP Free
The generate_content_more_link_output filter changes the HTML markup of the “Read more” link when a post uses the more tag, instead of an automatic excerpt.
Parameters: none — returns the full HTML string. Default:
sprintf( '<p class="read-more-container"><a title="%1$s" class="read-more content-read-more" 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() ) ),
__( 'Read more', 'generatepress' )
);
add_filter( 'generate_content_more_link_output', 'tu_change_content_more_link' );
function tu_change_content_more_link() {
return sprintf( '<p class="read-more-container MY-CUSTOM-CLASS"><a title="%1$s" class="read-more content-read-more" 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() ) ),
__( 'Read more', 'generatepress' )
);
}
Related: generate_excerpt_more_output · generate_more_jump Guide: Blog
generate_more_jump
GP Free
The generate_more_jump filter changes or removes the #more-x anchor added to “Read more” URLs when a post uses the more tag.
Parameters: $anchor (string). Default: #more-PAGEID.
add_filter( 'generate_more_jump', '__return_false' );
Related: generate_content_more_link_output Guide: Blog
Featured images
generate_featured_image_output
GP Free
The generate_featured_image_output filter changes the HTML markup of the featured image on posts, the blog and archives.
Parameters: $output (string, HTML). Default:
sprintf(
'<div class="post-image">
%3$s
<a href="%1$s">
%2$s
</a>
</div>',
esc_url( get_permalink() ),
get_the_post_thumbnail(
get_the_ID(),
apply_filters( 'generate_page_header_default_size', 'full' ),
$attrs
),
apply_filters( 'generate_inside_featured_image_output', '' )
)
add_filter( 'generate_featured_image_output', function( $output ) {
return sprintf(
'<div class="post-image">
%2$s
</div>',
esc_url( get_permalink() ),
get_the_post_thumbnail(
get_the_ID(),
apply_filters( 'generate_page_header_default_size', 'full' ),
array(
'itemprop' => 'image',
)
)
);
} );
add_filter( 'generate_featured_image_output', function( $output ) {
if ( ! is_category() ) {
return $output;
}
return sprintf(
'<div class="post-image">
%3$s
<a href="%1$s">
%2$s
</a>
</div>',
esc_url( get_the_post_thumbnail_url() ),
get_the_post_thumbnail(
get_the_ID(),
apply_filters( 'generate_page_header_default_size', 'full' )
),
apply_filters( 'generate_inside_featured_image_output', '' )
);
} );
Related: generate_inside_featured_image_output · generate_blog_image_attributes Guide: Blog — Featured images
generate_inside_featured_image_output
GP Free
The generate_inside_featured_image_output filter adds content inside the featured image wrapper, alongside the output of generate_featured_image_output.
Parameters: $output (string, HTML). Default: '' (empty string).
add_filter( 'generate_inside_featured_image_output', function( $output ) {
return $output . '<span class="featured-badge">Featured</span>';
} );
Related: generate_featured_image_output Guide: Blog — Featured images
generate_blog_image_attributes
GP Premium — Blog module.
The generate_blog_image_attributes filter changes the featured image’s attachment size attributes (width, height, crop) based on conditions you choose.
Parameters: $atts (array — width, height, crop, passed to wp_get_attachment_image). Default: built from the Blog module’s image size settings.
add_filter( 'generate_blog_image_attributes', function( $atts ) {
if ( is_post_type_archive( 'portfolio' ) ) {
$atts['width'] = 300;
$atts['height'] = 300;
$atts['crop'] = true;
}
return $atts;
} );
Related: generate_featured_image_output Guide: Blog — Featured images
Blog layout (GP Premium)
generate_blog_columns
GP Premium — Blog module.
The generate_blog_columns filter turns on column layout for a custom post type (columns are a Blog module setting for the standard post type).
Parameters: $columns (boolean, or true to force columns on). Default: the Blog module’s Columns setting.
add_filter( 'generate_blog_columns', function( $columns ) {
if ( 'CPT_SLUG' === get_post_type() && ! is_singular() ) {
return true;
}
return $columns;
} );
Related: generate_blog_masonry Guide: Blog — Columns and masonry
generate_blog_masonry
GP Premium — Blog module.
The generate_blog_masonry filter turns on masonry layout for a custom post type.
Parameters: $masonry (string, 'true' or 'false'). Default: 'false'.
add_filter( 'generate_blog_masonry', function( $masonry ) {
if ( is_post_type_archive( 'portfolio' ) ) {
return 'true';
}
return $masonry;
} );
Related: generate_blog_columns Guide: Blog — Columns and masonry