php - Is there anyway to add rel="next"/rel="prev" into "Page Template" with WordPress SEO by Yoast? -
our site using "wordpress seo yoast" rel="next"
, rel="prev"
working fine on category , archive page, in page template created, rel="next"
, rel="prev"
not showing. (this page template has pagination)
our website structure => have "article
" post type
in article have category
- credit card
- cash card
- loan
- etc.
as want url www.sitename.com/loan
without having ../category/loan
i created 'page' called 'loan' , using page-loan.php
page template query post type 'article' category 'loan'
i want have rel="next"
, rel="prev"
appear in page template wonder there anyway use wordpress seo yoast it?
or there anyway modify below script in plugin make rel="next"
, rel="prev"
appear in page template well?
the script found in plugin
public function adjacent_rel_links() { // don't genesis, way genesis handles homepage functionality different , causes issues sometimes. /** * filter 'wpseo_genesis_force_adjacent_rel_home' - allows devs allow echoing rel="next" / rel="prev" wp seo on genesis installs * * @api bool $unsigned whether or not 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 use index.php when needed, done after paged == 2 check prev links homepage 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 current page 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' ); } } } } /** * adjacent pages link archives * * @since 1.0.2 * * @param string $rel link relationship, prev or next. * @param string $url un-paginated url of current archive. * @param string $page page number add on $url $link tag. * @param boolean $incl_pagination_base whether or not 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 wp seo * * @api string $unsigned 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; } }
Comments
Post a Comment