Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Forked from katmoody/Custom-Grid-Loop-Excerpt
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GaryJones/2cf5e711bee56f11f3f8 to your computer and use it in GitHub Desktop.
Save GaryJones/2cf5e711bee56f11f3f8 to your computer and use it in GitHub Desktop.
<?php
add_action( 'genesis_entry_content', 'kat_grid_content', 9 );
/**
* Change the number of words in excerpt if in the grid loop and customize READ MORE, add accessibility.
*/
function kat_grid_content() {
// Make sure we're in the grid loop.
if ( ! apply_filters( 'is_genesis_grid_loop', false ) ) {
return;
}
// Change length of teaser.
$length = 55;
if ( in_array( 'teaser', get_post_class() ) ) {
$length = 25;
}
echo '<p>' . wp_trim_words( get_the_excerpt(), $length ) . '</p>';
// Display more link.
printf(
'<p class="more-link"><a href="%1$s">%2$s<span class="screen-reader-text"> %3$s %4$s</span></a></p>',
esc_url( get_permalink() ),
esc_html__( 'Read more', 'your-text-domain' ),
esc_html_x( 'about', 'i.e. Read more about A Post Title', 'your-text-domain' ),
esc_html( get_the_title() )
);
// Remove default content so we don't get both.
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment