"Read Next" Link Two Thirds Into Posts
Adds a "Read next" link to another post from the same category two thirds of the way through each article, keeping readers on your site.
Opens WPIDE on
Code
<?php
$wpide_read_next = get_posts( array(
'category__in' => wp_get_post_categories( get_the_ID() ),
'post__not_in' => array( get_the_ID() ),
'numberposts' => 1,
'ignore_sticky_posts' => true,
'no_found_rows' => true,
) );
if ( $wpide_read_next ) : ?>
<p class="wpide-read-next" style="margin:2em 0;padding:1em 1.25em;border-left:4px solid currentColor;background:rgba(0,0,0,.03);">
<strong>Read next:</strong>
<a href="<?php echo esc_url( get_permalink( $wpide_read_next[0] ) ); ?>"><?php echo esc_html( get_the_title( $wpide_read_next[0] ) ); ?></a>
</p>
<?php endif; ?>
Notes
The suggestion is the newest other post in the same category; nothing is shown if there is none.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.