Our site currently uses "WordPress SEO from Yoast" rel="next" and rel="prev" work fine on the category and archive page, however, the rel="next" and rel="prev" pages in our template do not display . (This page template also has pagination)
The structure of our site => we have < Article "Post type
in the article we have a category
- Credit card
- Cash card
- Loan
- and etc.
Since I want the url to be www.sitename.com/loan without ../category/loan
I created a “Page” called “Credit”, and using page-loan.php as the page template for the request type of type “Article” of the category “Credit”
I want rel="next" and rel="prev" be displayed in this page template. Interesting, anyway, to use Yoast's WordPress SEO to do this?
or change the script below in the plugin anyway to also make rel="next" and rel="prev" in the page template?
script I found in the plugin
public function adjacent_rel_links() { // Don't do this for Genesis, as the way Genesis handles homepage functionality is different and causes issues sometimes. /** * Filter 'wpseo_genesis_force_adjacent_rel_home' - Allows devs to allow echoing rel="next" / rel="prev" by WP SEO on Genesis installs * * @api bool $unsigned Whether or not to rel=next / rel=prev */ if ( is_home() && function_exists( 'genesis' ) && apply_filters( 'wpseo_genesis_force_adjacent_rel_home', false ) === false ) { return; } global $wp_query; if ( ! is_singular() ) { $url = $this->canonical( false, true, true ); if ( is_string( $url ) && $url !== '' ) { $paged = get_query_var( 'paged' ); if ( 0 == $paged ) { $paged = 1; } if ( $paged == 2 ) { $this->adjacent_rel_link( 'prev', $url, ( $paged - 1 ), true ); } // Make sure to use index.php when needed, done after paged == 2 check so the prev links to homepage will not have index.php erroneously. if ( is_front_page() ) { $url = wpseo_xml_sitemaps_base_url( '' ); } if ( $paged > 2 ) { $this->adjacent_rel_link( 'prev', $url, ( $paged - 1 ), true ); } if ( $paged < $wp_query->max_num_pages ) { $this->adjacent_rel_link( 'next', $url, ( $paged + 1 ), true ); } } } else { $numpages = 0; if ( isset( $wp_query->post->post_content ) ) { $numpages = ( substr_count( $wp_query->post->post_content, '<!--nextpage-->' ) + 1 ); } if ( $numpages > 1 ) { $page = get_query_var( 'page' ); if ( ! $page ) { $page = 1; } $url = get_permalink( $wp_query->post->ID ); // If the current page is the frontpage, pagination should use /base/ if ( $this->is_home_static_page() ) { $usebase = true; } else { $usebase = false; } if ( $page > 1 ) { $this->adjacent_rel_link( 'prev', $url, ( $page - 1 ), $usebase, 'single_paged' ); } if ( $page < $numpages ) { $this->adjacent_rel_link( 'next', $url, ( $page + 1 ), $usebase, 'single_paged' ); } } } } /** * Get adjacent pages link for archives * * @since 1.0.2 * * @param string $rel Link relationship, prev or next. * @param string $url the un-paginated URL of the current archive. * @param string $page the page number to add on to $url for the $link tag. * @param boolean $incl_pagination_base whether or not to include /page/ or not. * * @return void */ private function adjacent_rel_link( $rel, $url, $page, $incl_pagination_base ) { global $wp_rewrite; if ( ! $wp_rewrite->using_permalinks() ) { if ( $page > 1 ) { $url = add_query_arg( 'paged', $page, $url ); } } else { if ( $page > 1 ) { $base = ''; if ( $incl_pagination_base ) { $base = trailingslashit( $wp_rewrite->pagination_base ); } $url = user_trailingslashit( trailingslashit( $url ) . $base . $page ); } } /** * Filter: 'wpseo_' . $rel . '_rel_link' - Allow changing link rel output by WP SEO * * @api string $unsigned The full `<link` element. */ $link = apply_filters( 'wpseo_' . $rel . '_rel_link', '<link rel="' . esc_attr( $rel ) . '" href="' . esc_url( $url ) . "\" />\n" ); if ( is_string( $link ) && $link !== '' ) { echo $link; } }