Skip to content

Instantly share code, notes, and snippets.

@danielcharrua
Last active December 9, 2023 23:29
Show Gist options
  • Select an option

  • Save danielcharrua/d2947ded484c4c19b173f7f9aa6ff547 to your computer and use it in GitHub Desktop.

Select an option

Save danielcharrua/d2947ded484c4c19b173f7f9aa6ff547 to your computer and use it in GitHub Desktop.
Add thumbnail to Next Post/ Previous post on Astra Theme
<?php
/**
* Add thumbnail to Next Post/ Previous post.
*
* @param array $args Arguments for next post / previous post links.
* @return array
*/
function astra_change_next_prev_text( $args ) {
$next_post = get_next_post();
$prev_post = get_previous_post();
$next_text = false;
if ( $next_post ) {
$next_text = sprintf(
'%s <span class="ast-right-arrow">→</span> %s',
$next_post->post_title,
get_the_post_thumbnail( $next_post, 'small' )
);
}
$prev_text = false;
if ( $prev_post ) {
$prev_text = sprintf(
'<span class="ast-left-arrow">←</span> %s %s',
$prev_post->post_title,
get_the_post_thumbnail( $prev_post, 'small' ),
);
}
$args['next_text'] = $next_text;
$args['prev_text'] = $prev_text;
return $args;
}
add_filter( 'astra_single_post_navigation', 'astra_change_next_prev_text' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment