WP Developer
WP Developer

Reputation: 11

How to remove "?et_blog" pagination links parameter on Divi Custom Post Type?

In my Project i'm using DIVI theme and i have use multiple custom post type like recipe, articles and so on. and requirement is display that post in category archive page using pagination (without ajax) but after doing code.

if I remove "?et_blog" from url then page returning 404 error don't know why this adding please let me know if any solution is there ?

eg.url structure

I need to remove ?et_blog from URL

I'd try to add custom pagination and create shortcode function and display shortcode on DIVI builder

Upvotes: 1

Views: 1311

Answers (1)

The problem is related to divi blog, the pagination is managed by ajax , so the issue is about disable ajax pagination in DIVI builder.

The official documentation about this issue can be found here:

https://help.elegantthemes.com/en/articles/8570102-how-to-disable-the-ajax-pagination-for-the-blog-module-using-the-wp-pagenavi-plugin

https://help.elegantthemes.com/en/articles/2912512-how-to-disable-ajax-pagination-in-the-blog-module

None of the previous solution solved my problem, I also contacted divi support about this issue and the only option to fix the issue is using the default wordpress blog system:

To use the default blog template, please create a blog page by navigating to Pages > Add New Page and, select it under Settings > Reading > Your homepage displays > Post Page.

This is the first solution that works in terms of "disable ajax pagination" but you have to edit the new blog page using wordpress default editor instead of divi.

So the final solution that works for me is adding the following code to the functions.php, take in mind I use the plugin "wp-pagenavi-plugin" to show number is the pagination section under the blog module. This is the official plugin page: https://wordpress.org/plugins/wp-pagenavi/

// 1. Remove the ?et_blog parameter from pagination links
function remove_et_blog_from_pagination_links($link) {
    return remove_query_arg('et_blog', $link);
}
add_filter('paginate_links', 'remove_et_blog_from_pagination_links');
add_filter('et_pb_filter_pagination_url', 'remove_et_blog_from_pagination_links');

// 2. Redirect URLs containing the ?et_blog parameter to a clean URL
function redirect_remove_et_blog() {
    if (isset($_GET['et_blog'])) {
        wp_redirect(remove_query_arg('et_blog'), 301);
        exit;
    }
}
add_action('template_redirect', 'redirect_remove_et_blog');

// 3. Dynamically clean ?et_blog from pagination links using JavaScript
function custom_pagination_script() {
    ?>
    <script>
        document.addEventListener('DOMContentLoaded', () => {
            // Function to clean pagination links
            function updatePaginationLinks() {
                const paginationLinks = document.querySelectorAll('.wp-pagenavi a');
                paginationLinks.forEach(link => {
                    const href = link.getAttribute('href');
                    if (href && href.includes('?et_blog')) {
                        const newHref = href.replace('?et_blog', '');
                        link.setAttribute('href', newHref);
                    }
                });
            }

            // Clean links on the initial page load
            updatePaginationLinks();

            // Observe the DOM for changes (e.g., AJAX-loaded pagination links)
            const observer = new MutationObserver(() => {
                updatePaginationLinks();
            });

            observer.observe(document.body, {
                childList: true,
                subtree: true
            });
        });
    </script>
    <?php
}
add_action('wp_footer', 'custom_pagination_script');

Upvotes: 0

Related Questions