Resolved - wordpress pagination adds extra slashes to url in post or category

I am working on blog where pagination is not working correct. All is working but when I click to the next page the url will get a extra slash in the URL, not sure why this is happening but when using the pagination a lot will add every time a new slash to the URL.


URL Links are like this:

mysite.com/blog/ ,
mysite.com/blog//page/2,
mysite.com/blog///page/3,
mysite.com/blog////page/4

You are using this code probably:

===============================
 $total_pages = $loop->max_num_pages;

    if ($total_pages > 1){

        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => '/page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
            'prev_text'    => __('« prev'),
            'next_text'    => __('next »'),
        ));
    }   
}
=====================================

SO i figured out how to solve this not to add extra slashes every time when we click on a pagination URL

To remove extra slash replace this code to the existing one

==========================================
$total_pages = $loop->max_num_pages;
    $burl = get_pagenum_link(1);
    if(substr($burl , -1)=='/'){
        $burl = rtrim($burl,'/\\');
    }

    if ($total_pages > 1){

        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => $burl . '%_%',
            'format' => '/page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
            'prev_text'    => __('« prev'),
            'next_text'    => __('next »'),
        ));
    }   
}



I hope this will work.

If this work please don't forget to add a comment by saying thanks.

Comments