Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1463614

    Hi Enfold,

    Today I received a message that told me that certain pages that use pagination are not indexed by Google because I put a canonical tag to the original page. So our /blog page has a canonical URL set, but for best practice the pagination parameters in the URL all should have their own canonical URL. We are currently using Yoast for our theme, that state that they do this automatically but it does not seem to work for the Avia Element.

    Question 1: How do I adjust this so that the avia elements are indexed correctly by Google?
    Question 2: Can I change the name of the element to just ‘page’ so instead of blog/?avia-element-paging=2 it could be come /blog/page-2?

    Looking forward to your response!

    Kind regards,
    Joost

    #1463729

    Hey dp-beheer,
    Thanks for your question, the correct pagination url is /?avia-element-paging=2 this can not be changed to /page-2 as it would be a conflict with the WordPress pagination. I don’t see anything on the Pagination Best Practices page to point to a diffidence between /?avia-element-paging=2 and /page-2. Nonetheless, if you would like to request this pagination change, the Dev Team has opened a new Github Feature Request for users to place requests and follow them as the Dev Team reviews them.

    Best regards,
    Mike

    #1463928

    Hi Mike,

    Thanks for your reply! Noted that we can’t change the avia-element-paging name! For the SEO best practice, this was regarding this sentence:
    Don’t use the first page of a paginated sequence as the canonical page. Instead, give each page in its own canonical URL.

    The blog on our page has the following slug: /blog/?avia-element-paging=2 but the canonical URL for this is still *URL removed*. According to Google’s best practice for paging, this should be:
    “Google is very clear now: each page within a paginated series should canonicalize to itself, so /page/2/ has a canonical pointing to /page/2/.”

    We have the Yoast plug-in installed at this moment, but that does not seem to be adding the right canonical url to the pagination page. What could I do for this issue to work?

    Kind regard,
    Joost

    • This reply was modified 3 weeks ago by Mike. Reason: removed url per user request
    #1463982

    Hi,
    Unfortunately, this can not be changed without causing a conflict with the WordPress pagination.
    I asked the Dev Team again today and they said that this is still true.

    Best regards,
    Mike

    #1480710

    Hi Mike,

    A small update on this. What I want to achieve is not to change the URL structure, but rather that each paginated is pointing towards itself as a canonical page. Then, the Yoast plug-in also advises to add rel=next and rel=prev tags to the pagination buttons.

    You can read more about that here: https://yoast.com/help/is-the-plugin-compatible-with-paginated-content/
    And here is a Github link to the implementation: https://gist.github.com/amboutwe/66c583d2ef4015a8a244ee3e0e8cd1a0

    There is also another ticket that links to this: https://kriesi.at/support/topic/alternate-page-with-correct-canonical-tag/.

    I tried, based on the documentation, to alter the Yoast plug-in to take the avia-pagination into account when adding it’s logic, both canonical wise and with the prev/next rel’s.

    Could you guide me in the right direction with this:

    <?php
    /**
     * Fix Yoast SEO pagination compatibility with Enfold theme using avia-element-paging.
     *
     * This will:
     * - Override the canonical URL to point to the current paginated URL
     * - Add correct rel="next" and rel="prev" links for Yoast SEO
     * - Handle first page navigation properly
     * - Work with multiple Enfold paginated pages
     */
    
    // Store max pages in a more efficient way
    global $avia_pagination_data;
    $avia_pagination_data = [];
    
    // More efficient way to store max pages without creating duplicate queries
    add_filter('avia_blog_post_query', function($query, $params) {
        global $avia_pagination_data;
        
        // Store the page ID so we can track pagination for multiple pages
        $page_id = get_the_ID();
        if (!isset($avia_pagination_data[$page_id])) {
            $avia_pagination_data[$page_id] = [];
        }
        
        // We don't need to create a new query object here
        // Just extract the pagination data from the query args
        if (isset($query['posts_per_page']) && isset($params['items'])) {
            $posts_per_page = intval($query['posts_per_page']);
            $total_items = intval($params['items']);
            
            if ($posts_per_page > 0) {
                $max_pages = ceil($total_items / $posts_per_page);
                $avia_pagination_data[$page_id]['max_pages'] = $max_pages;
            }
        }
        
        return $query;
    }, 20, 2);
    
    /**
     * Helper function to check if we're on an Enfold paginated page
     */
    function is_enfold_paginated_page() {
        // Check if we're on a singular page that might have pagination
        if (!is_singular()) {
            return false;
        }
        
        // Check for the pagination parameter
        $has_param = isset($_GET['avia-element-paging']);
        
        // Also check if the page content contains Enfold pagination elements
        $content = get_post_field('post_content', get_the_ID());
        $has_pagination_element = (
            strpos($content, 'blog') !== false || 
            strpos($content, 'portfolio') !== false ||
            strpos($content, 'av_masonry_entries') !== false
        );
        
        return $has_param || $has_pagination_element;
    }
    
    /**
     * Get current page and max pages for the current Enfold page
     */
    function get_enfold_pagination_data() {
        global $avia_pagination_data;
        $page_id = get_the_ID();
        
        $current_page = isset($_GET['avia-element-paging']) ? intval($_GET['avia-element-paging']) : 1;
        $max_pages = isset($avia_pagination_data[$page_id]['max_pages']) ? 
                     $avia_pagination_data[$page_id]['max_pages'] : 
                     10; // Fallback value
                     
        return [
            'current' => $current_page,
            'max' => $max_pages
        ];
    }
    
    /**
     * Fix canonical URL for Enfold pagination
     */
    add_filter('wpseo_canonical', function($canonical) {
        if (!is_enfold_paginated_page()) {
            return $canonical;
        }
        
        $data = get_enfold_pagination_data();
        $current_page = $data['current'];
        
        // Only modify if we're on a paginated page
        if ($current_page > 1) {
            return add_query_arg('avia-element-paging', $current_page, get_permalink());
        }
        
        return $canonical;
    });
    
    /**
     * Fix prev link for Enfold pagination
     */
    add_filter('wpseo_prev_rel_link', function($link) {
        if (!is_enfold_paginated_page()) {
            return $link;
        }
        
        $data = get_enfold_pagination_data();
        $current_page = $data['current'];
        
        if ($current_page > 1) {
            $prev_page = $current_page - 1;
            $prev_url = ($prev_page === 1) ? 
                       get_permalink() : 
                       add_query_arg('avia-element-paging', $prev_page, get_permalink());
                       
            return '<link rel="prev" href="' . esc_url($prev_url) . '" />' . PHP_EOL;
        }
        
        return false;
    });
    
    /**
     * Fix next link for Enfold pagination
     */
    add_filter('wpseo_next_rel_link', function($link) {
        if (!is_enfold_paginated_page()) {
            return $link;
        }
        
        $data = get_enfold_pagination_data();
        $current_page = $data['current'];
        $max_pages = $data['max'];
        
        if ($current_page < $max_pages) {
            $next_page = $current_page + 1;
            $next_url = add_query_arg('avia-element-paging', $next_page, get_permalink());
            
            return '<link rel="next" href="' . esc_url($next_url) . '" />' . PHP_EOL;
        }
        
        return false;
    });
    
    /**
     * Also fix first page navigation (when no pagination parameter is present)
     */
    add_action('wp_head', function() {
        // Only run on first page (no pagination parameter)
        if (is_enfold_paginated_page() && !isset($_GET['avia-element-paging'])) {
            $data = get_enfold_pagination_data();
            $max_pages = $data['max'];
            
            // Only add next link if we have more than one page
            if ($max_pages > 1) {
                $next_url = add_query_arg('avia-element-paging', 2, get_permalink());
                echo '<link rel="next" href="' . esc_url($next_url) . '" />' . PHP_EOL;
            }
        }
    }, 999); // Run late to ensure it doesn't get overridden
    

    Would be greatly appreciated, as this would solve the GSC notifications and let the pagination target to itself.

    Kind regards,
    Joost

    #1480711
    This reply has been marked as private.
    #1480739

    Hi,
    I removed the url from the August 6, 2024 post

    Best regards,
    Mike

    #1480919

    Hi Mike,

    Thanks! Do you also have a solution for my problem stated above my reply about the link?

    Thanks in advance!

    Kind regards,
    Joost

    #1481209

    Hi,
    If you are asking about “Question 2” changing the link from /?avia-element-paging=2 to /page-2 can not be done, as it causes a conflict with WordPress.
    The Dev Team set it to /?avia-element-paging=2 to avoid this conflict.
    Nonetheless, if you would like to request this pagination change, the Dev Team has opened a new Github Feature Request for users to place requests and follow them as the Dev Team reviews them.

    Best regards,
    Mike

    #1481432

    Hi Mike,

    Are you able to see the reply I posted on April 3, 2025 at 11:56 am? Because you are referring to question 2, I think you may not have seen my message. There I am explaining what I am trying to achieve.

    Looking forward to your reply.

    Kind regards,
    Joost

    #1481639

    Hi,
    Sorry, your “April 3” post script looks like you are trying to change the pagination, this will cause a conflict with the WordPress pagination.
    If I misunderstand, please explain further.

    Best regards,
    Mike

    #1481814

    Hi Mike,

    It seems that Yoast is not integrate well with the Enfold pagination as certain tags should be added to paginated content to avoid canonical tag problems. Yoast outline the best practices for this. The example, we currently have a blog page, with avia-element-pagination, link is in the private content section.

    On both pages, the canonical URL refers to the /blog main page, but it should link to itself. So the /blog/?avia-element-paging=2 should also link to itself regarding canonical tags. That is what is nu automatically happening right now, because of the way that the pagination is being treated.

    That is what I would like some support about. Is it not the changing of the pagination, rather the addition of the correct tags. So the avia-element-paging can stay as it is.

    Looking forward to your reply.

    Kind regards,
    Joost

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.