-
AuthorPosts
-
January 6, 2019 at 8:47 am #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.
January 8, 2019 at 6:19 am #1051202Hey 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,
IsmaelJanuary 8, 2019 at 7:01 am #1051233Hi,
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, 10 months ago by Yoursefzade.
January 9, 2019 at 9:17 am #1051650Hi 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.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.January 9, 2019 at 4:31 pm #1051905Hi 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,
VictoriaJanuary 10, 2019 at 6:53 am #1052193Hi,
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,
January 10, 2019 at 6:44 pm #1052438Hi 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,
VictoriaJanuary 12, 2019 at 8:06 am #1053015Hi,
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.
January 12, 2019 at 9:00 am #1053022Because 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.January 14, 2019 at 3:09 am #1053490Hi,
Have you tried this option?
// https://kriesi.at/support/topic/paginated-pages-not-showing-relnext-and-relprev/#post-925305
Best regards,
IsmaelJanuary 14, 2019 at 8:42 am #1053573Hi 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, 10 months ago by Yoursefzade.
January 15, 2019 at 12:15 am #1053880Hi,
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,
IsmaelJanuary 15, 2019 at 6:59 am #1053971Hi 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.
January 18, 2019 at 1:05 pm #1055438Hi,
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,
IsmaelJanuary 19, 2019 at 7:49 am #1055797Hi Ismael,
Thank you, but it’s not work for last page. you can see it in this link:
https://ariamedtour.com/video-testimonialsJanuary 21, 2019 at 2:31 pm #1056666Hi,
Can we access your file server? I would like to debug the code.
Best regards,
IsmaelJanuary 21, 2019 at 2:58 pm #1056697Hi Ismael
Please see Private contentthank you
January 24, 2019 at 3:43 am #1058010Hi,
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,
IsmaelJanuary 24, 2019 at 6:30 am #1058027Hi 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” ).January 25, 2019 at 8:09 am #1058520Hi,
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,
IsmaelJanuary 25, 2019 at 2:41 pm #1058756Hi 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.
January 28, 2019 at 6:46 am #1059529Hi,
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,
IsmaelJanuary 28, 2019 at 7:48 am #1059537Hi 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?
Best regards,
January 29, 2019 at 12:53 pm #1059976Hi 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.
January 31, 2019 at 12:22 pm #1060922Hi,
Try to create an array with key value pair.
array ( 0 => '6084', 1 => '5880' ),
Best regards,
IsmaelFebruary 2, 2019 at 7:16 am #1061884Hi 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, 9 months ago by Yoursefzade.
February 5, 2019 at 3:36 pm #1063199Hi,
I added the category ids in the array. Please remove the browser cache prior to checking the page.
Best regards,
IsmaelFebruary 6, 2019 at 7:23 am #1063475Hi 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.
February 7, 2019 at 9:55 am #1063964Hi,
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 -
AuthorPosts
- The topic ‘Problem about rel next/ previous in pagination’ is closed to new replies.