Tagged: blog pages, pagination, rel
-
AuthorPosts
-
April 27, 2023 at 10:31 pm #1405879
I implemented fixes from a previous thread https://kriesi.at/support/topic/problem-about-rel-next-previous-in-pagination/
and it ALMOST works but my resulting rel=”next” and rel=”prev” href= excludes the “h” in https:// address as well as adds a “p” to page/#
I only require this solution for the Blog Pages (multiple pages need to be indexed). My Yoast plugin works great for any archived blog posts (in categories) but not for the main blog page posts.
Please help! I am almost there!
April 28, 2023 at 4:13 am #1405895This is the code I need to debug:
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;
}It is resulting in <link rel=”next” href=”ttps://mylinkhere/blog/ppage/3″ />
How can I get it to show https and take out the extra “p” in pages?
@ISMAEL are you available to assist?April 28, 2023 at 5:57 am #1405906Hi,
Thank you for the inquiry.
We may need to inspect the site in order to understand the issue better. Please provide the site details in the private field.
If you need a quick fix, please look for this code in the previous filter.
$link_prev = $url . ‘page/’ . ($page – 1); $link_next = $url . ‘page/’ . ($page + 1);
Replace it with:
$link_prev = str_replace("ppage", "page", $link_prev); $link_next = str_replace("ppage", "page", $link_next);
Best regards,
IsmaelApril 28, 2023 at 5:25 pm #1405947This reply has been marked as private.April 28, 2023 at 5:27 pm #1405949This didn’t work. It works for all but first and last pages when I put:
$url = (isset($_SERVER[‘HTTPS’]) ? “hhttps” : “http”) . “://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]”;
$link_prev = $url . ‘age/’ . ($page – 1);
$link_next = $url . ‘age/’ . ($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;
}April 30, 2023 at 3:46 pm #1406052Hi,
Thanks for the link to your site, I see that you are using Enfold v4.7.5 with WordPress v6.1.1 and PHP v8.1.18
Enfold v4.7.5 is not PHP v8+ or WP 6+ ready, please update to Enfold v5.5
Before updating please remove the header.php from your child theme as it will most likely cause issues, we don’t recommend adding header.php or footer.php to child themes anymore as this is the top reason for crashes when updating.Best regards,
Mike -
AuthorPosts
- You must be logged in to reply to this topic.