Viewing 29 posts - 1 through 29 (of 29 total)
  • Author
    Posts
  • #1050532

    Hi,

    I have use below code for rel next/ previous:

    add_action('wp_head', 'wp_head_pagination_mod');
    function wp_head_pagination_mod() {
        $page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' );
    
        if( ! $page ) return;
    
        $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
        $url = substr($url, 1, strpos($url, "page"));
    
        $link_prev = $url . 'page/' . ($page - 1);
        $link_next = $url  . 'page/' . ($page + 1);
    
        $output  = ' 	<link rel="prev" href="'. $link_prev .'" />' . PHP_EOL;
        $output .= ' 	<link rel="next" href="'. $link_next .'" />' . PHP_EOL;
        echo $output;
    }

    But my problem is when i’m in first page it’s not assign to rel=”next” and when i’m in last page it’s not assign to rel=”prev” page. it’s important for me help me for solved this problem.

    thank you.

    #1051202

    Hey ariamedtour,

    Thank you for using Enfold.

    That is how it’s supposed to work. You don’t need the rel attribute on the first page.

    // https://yoast.com/rel-next-prev-paginated-archives/

    Best regards,
    Ismael

    #1051233

    Hi,

    i found this Indicating paginated content to Google on link below:

    https://support.google.com/webmasters/answer/1663744?hl=en

    in this page you see example in table cats_part_1 cats_part_2 cats_part_3 in cats_part_1 <link rel=”next” href=”cats_part_2> and in cats_part_2 <link rel=”next” href=”cats_part_3> <link rel=”prev” href=”cats_part_1> and in cats_part_3 <link rel=”prev” href=”cats_part_2>

    please see link and tell me about it.

    thank you.

    • This reply was modified 5 years, 4 months ago by Yoursefzade.
    #1051650

    Hi again,
    image below is according to https://support.google.com/webmasters/answer/1663744?hl=en about rel=”next” in first page and rel=”prev” in last page.

    Indicating paginated content to Google

    Some explain for my problem. i use blog posts element to show some posts in category on my site.
    When i use rel=”next” and rel=”prev” code in my site. First page need rel=”next” according to this link https://support.google.com/webmasters/answer/1663744?hl=en and last page only need rel=”prev” but in my site first page doesn’t have rel=”next” and last page have two rel=”next” and rel=”prev”.

    please see my some page i use blog posts element to show some posts in category:
    https://ariamedtour.com/weight-loss-photos
    https://ariamedtour.com/blog
    thank you.

    #1051905

    Hi ariamedtour,

    You need to add the condition, if it’s a page don’t add rel=”prev” and if it’s the last page don’t add the rel=”next” in your wp_head_pagination_mod function.

    Also with this code you might get page 0 or page that is more than the number of pages that you have:

    
        $link_prev = $url . 'page/' . ($page - 1);
        $link_next = $url  . 'page/' . ($page + 1);
    

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #1052193

    Hi,
    The problem is i don’t know how add this condition to wp_head_pagination_mod function.
    Please help me to solved this problem that important to me.

    Thank you,

    #1052438

    Hi ariamedtour,

    It is kind of the scope of the support that we provide here. It is easy to do for the rel=”prev”, for the other part, there is no way of knowing in this code how many pages there are and so we don’t know when it is the last page.

    You might want to hire a dev to do it for you.

    Best regards,
    Victoria

    #1053015

    Hi,

    I use Ismael’s code in this topic for my site

    https://kriesi.at/support/topic/paginated-pages-not-showing-relnext-and-relprev/

    If Ismael said to me how can i define this condition for my site is very good.

    Thank you.

    #1053022

    Because of this problem and when i use blog post element in my post and set pagination to yes. it’s generate unlimited page in background and do not show but crawler see it and crawl it. for example in this link: https://ariamedtour.com/video-testimonials you see 5 pages but if you change to https://ariamedtour.com/video-testimonials/page/80 in address bar you see page without any content and this is bad for seo.
    Please help for those issues.

    #1053490
    #1053573

    Hi Ismael,
    Yes but because of my permalink structures i can’t “Remove the categories prefix” in the Yoast seo. and this setting is n’t solved my problem.

    It’s not complicated, in page one rel=”next” and when in last page only rel=”prev” needed like that i said before.

    In archive pages Yoast seo implement this code correctly. but when i use blog post element or other element that have pagination this problem Occurred.

    Thank you.

    • This reply was modified 5 years, 3 months ago by Yoursefzade.
    #1053880

    Hi,

    Thanks for the update.

    Replace the previous code with the following:

    add_action('wp_head', 'wp_head_pagination_mod');
    function wp_head_pagination_mod() {
        global $wp_query;
        
        $page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' );
        $page = ! $page ? 0 : $page;
    
        $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
        $url = substr($url, 1, strpos($url, "page"));
    
        $link_prev = $url . 'page/' . ($page - 1);
        $link_next = $url  . 'page/' . ($page + 1);
    
        if( ! $page ) {
            $output .= ' 	<link rel="next" href="'. $link_next .'" />' . PHP_EOL;   
        } else if( $page == $wp_query->max_num_pages ) {
            $output  = ' 	<link rel="prev" href="'. $link_prev .'" />' . PHP_EOL;
        } else {
            $output  = ' 	<link rel="prev" href="'. $link_prev .'" />' . PHP_EOL;
            $output .= ' 	<link rel="next" href="'. $link_next .'" />' . PHP_EOL;
        }
    
        echo $output;
    }

    Best regards,
    Ismael

    #1053971

    Hi Ismael,

    Thank you for this code. its solved for page/1 but for last page yet have a rel=”next” and rel”prev” how can solved this problem for last page?

    In last page should only have a rel=”prev”

    Thank you.

    #1055438

    Hi,

    I adjusted it again added a condition for the last page.

    add_action('wp_head', 'wp_head_pagination_mod');
    function wp_head_pagination_mod() {
        global $wp_query;
    
        $page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' );
        $page = ! $page ? 0 : $page;
    
        $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
        $url = substr($url, 1, strpos($url, "page"));
    
        $link_prev = $url . 'page/' . ($page - 1);
        $link_next = $url  . 'page/' . ($page + 1);
    
        if( ! $page ) {
            $output .= ' 	 	<link rel="next" href="'. $link_next .'" />' . PHP_EOL;   
        } elseif( $page == $wp_query->max_num_pages ) {
            $output  = ' 	 	<link rel="prev" href="'. $link_prev .'" />' . PHP_EOL;
        } else {
            $output  = ' 	 	<link rel="prev" href="'. $link_prev .'" />' . PHP_EOL;
            $output .= ' 	 	<link rel="next" href="'. $link_next .'" />' . PHP_EOL;
        }
    
        echo $output;
    }

    Best regards,
    Ismael

    #1055797

    Hi Ismael,

    Thank you, but it’s not work for last page. you can see it in this link:
    https://ariamedtour.com/video-testimonials

    #1056666

    Hi,

    Can we access your file server? I would like to debug the code.

    Best regards,
    Ismael

    #1056697

    Hi Ismael
    Please see Private content

    thank you

    #1058010

    Hi,

    Where did you add the code? I can’t find it in the functions.php file.
    I also noticed that you’re not using a child theme. It is highly recommended to create one for every WordPress installation.

    // https://kriesi.at/documentation/enfold/child-theme/#how-child-themes-work

    Best regards,
    Ismael

    #1058027

    Hi Ismael,
    Please login in ftp account again and download functions.php in line 726 you can find your code. I write comment for your code ( //for rel=”next” and rel=”prev” ).

    #1058520

    Hi,

    Thanks. I modified the code a bit. It’s now displaying the “rel=prev” without the “rel=next” attribute on the last page.

    Best regards,
    Ismael

    #1058756

    Hi Ismael,

    Thank you for your support. it’s work on https://ariamedtour.com/video-testimonials but does not work on https://ariamedtour.com/blog both of this page have a same (Blog Post Element) but different category.

    #1059529

    Hi,

    Edit the code and look for the tax_query. Just change the value of the “terms” field to the category of your blog. You can use an array of category id or slug.

    // https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

    Best regards,
    Ismael

    #1059537

    Hi Ismael,
    Thank you for your support.

    I have other question about (Blog Element). Why when i activate pagination in (Blog Element) and have a 5 pages if i change URL to 6th pages or above it’s not redirect to first page.Even i change URL to page/50 it’s show page with no content you can see picture below.Google alert me for this issue. what can i do for this problem?
    Page 50

    Best regards,

    #1059976

    Hi Ismael,
    In your tax_query code below:

    		'tax_query' =>
    		array (
    		  0 =>
    		  array (
    			'taxonomy' => 'category',
    			'field' => 'id',
    			'terms' =>
    			array (
    			  0 => '6084',
    			),
    			'operator' => 'IN',
    		  ),
    		),

    In ‘terms’ I’m adding multiple terms id like your reference: ‘terms’ => array( 6084, 5880, 9227 ). But does n’t work in multiple categories.it’s seems something went wrong in your code.

    Thank you.

    #1060922

    Hi,

    Try to create an array with key value pair.

    array (
      0 => '6084',
      1 => '5880'
    ),
    

    Best regards,
    Ismael

    #1061884

    Hi Ismael

    Thank you for your support. i try your sample code but it’s not work
    how can solved this issues?
    Best regards,

    • This reply was modified 5 years, 3 months ago by Yoursefzade.
    #1063199

    Hi,

    I added the category ids in the array. Please remove the browser cache prior to checking the page.

    Best regards,
    Ismael

    #1063475

    Hi Ismael,

    I remove the browser cache and test it in private window but if you see this url:
    https://ariamedtour.com/video-testimonials/page/5
    The last page still have a rel=”next”

    Thank you.

    #1063964

    Hi,

    What is the id of the category for the testimonial videos? I tried to access the site but the login page doesn’t exist. Please create a new ticket with the login credentials. We’ll close this thread now because it’s getting a bit too long. Let’s continue on the next thread.

    Best regards,
    Ismael

Viewing 29 posts - 1 through 29 (of 29 total)
  • The topic ‘Problem about rel next/ previous in pagination’ is closed to new replies.