Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if( ! function_exists( 'videotube_child_add_rel_custom_page' ) ){
- /**
- * Add the rel meta tag into header.
- */
- function videotube_child_add_rel_custom_page() {
- global $post;
- if( ! is_singular() || ! isset( $post->post_content ) ){
- return;
- }
- if( defined( 'PHP_VERSION' ) && version_compare( PHP_VERSION , '5.3.0', '<' ) ){
- return;
- }
- if( has_shortcode( $post->post_content , 'videotube' ) && strpos( $post->post_content , 'navigation="on"') ){
- $max_num_pages = (int)get_post_meta( $post->ID, 'custom_max_num_pages', true );
- if( $max_num_pages == 0 ){
- return;
- }
- add_filter( 'wpseo_canonical' , '__return_null' );
- $page_var = is_front_page() ? 'page' : 'paged';
- $paged = get_query_var( $page_var ) ? get_query_var( $page_var ) : 2;
- if( ! is_paged() ){
- // add the next tag
- add_action( 'wpseo_head' , function() use( $paged, $max_num_pages ){
- echo '<link rel="canonical" href="'. esc_url( get_permalink( $post->ID ) ) .'">';
- if( $max_num_pages > 1 ){
- echo '<link rel="next" href="'. esc_url( add_query_arg( array( 'paged' => $paged ), get_permalink( $post->ID ) ) ) .'">';
- }
- });
- }
- else{
- add_action( 'wpseo_head' , function() use( $paged, $max_num_pages ){
- echo '<link rel="canonical" href="'. esc_url( add_query_arg( array( 'paged' => $paged ), get_permalink( $post->ID ) ) ) .'">';
- echo '<link rel="prev" href="'. esc_url( add_query_arg( array( 'paged' => $paged - 1 ), get_permalink( $post->ID ) ) ) .'">';
- if( $max_num_pages >= ( $paged + 1 ) ){
- echo '<link rel="next" href="'. esc_url( add_query_arg( array( 'paged' => $paged + 1 ), get_permalink( $post->ID ) ) ) .'">';
- }
- });
- }
- }
- }
- add_action( 'wp', 'videotube_child_add_rel_custom_page', 21 );
- }
Advertisement
Add Comment
Please, Sign In to add comment