• Resolved renanbessa

    (@renanbessa)


    Is there any way to enable pagination in comments only on amp pages?

    Scenario: In our business we don’t want the pagination of comments on non-amp pages.

    We enable the paging option within wordpress discussion, so is there a way that this paging only works on amp pages?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Good question. It may be possible to use a custom function along with amp_is_request, or there may be plugins with such functionality. Please allow us some time to check this before reporting back to you here. In the meantime can you share your site URL or what theme you have active?

    Can you please try the below, added to a child themes function.php, a custom plugin or an insert snippets plugin:

    add_action(
        'wp',
        function() {
    
            add_filter(
                'option_page_comments',
                function( $page_comments ) {
                    if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
                        $page_comments = 1;
                    }
                    return $page_comments;
                }
            );
    
            add_filter(
                'option_comments_per_page',
                function( $comments_per_page ) {
                    if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
                        $comments_per_page = 5; // number comments to show.
                    }
                    return $comments_per_page;
                }
            );
    
        }
    );

    Let me know how you get on after trying it out.

    Thread Starter renanbessa

    (@renanbessa)

    Thanks a lot James! Perfect!

    Glad to hear it! Reach out if you have any further queries, and if you’ve been using the AMP plugin for a while be sure to leave your plugin feedback.

    Plugin Author Weston Ruter

    (@westonruter)

    Note: It’s probably not necessary to wrap the filters in a wp action since they shouldn’t be called before then. But it doesn’t hurt!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Enable comments pagination only amp page’ is closed to new replies.