Viewing 2 replies - 1 through 2 (of 2 total)
  • @ammadali If looking to implement pagination for your reader mode AMP URLs you can add the below to your current reader mode templates.
    <?php the_post_navigation(); ?>

    An ideal placement would be within the single.php template.

    You can then add the below to your themes functions.php to ensure each links directs users to their AMP version:

    add_filter( 'post_link', function( $url, $post ) {
    	static $recursing = false;
    	if ( $recursing ) {
    		return $url;
    	}
    	$recursing = true;
    	if ( ! function_exists( 'post_supports_amp' ) || ! post_supports_amp( $post ) ) {
    		return $url;
    	}
    	if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() && post_supports_amp( $post ) ) {
    		$url = amp_get_permalink( $post->ID );
    	}
    	$recursing = false;
    	return $url;
    }, 10, 2 );

    You’ll need to style the links to suit your needs. You’ll find more on pagination with some examples here.

    Plugin Author Weston Ruter

    (@westonruter)

    Actually, as opposed to using the post_link filter, you can instead just enable AMP-to-AMP linking, which is disabled by default in Reader mode.

    You can enable it with this code:

    add_filter( 'amp_to_amp_linking_enabled', '__return_true' );

    Then the Next/Previous links should automatically link to the AMP versions.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Add Next Button’ is closed to new replies.