phpface

videotube_child_filter_wpseo_set_canonical

Jun 11th, 2020
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. if( ! function_exists( 'videotube_child_filter_wpseo_set_canonical' ) ){
  2.     /**
  3.      *
  4.      * Filter wpSeo canonical URL
  5.      *
  6.      * @param  url $canonical
  7.      * @return url
  8.      *
  9.      *
  10.      * @author phpface
  11.      *
  12.      * @since 1.0.0
  13.      *
  14.      */
  15.     function videotube_child_filter_wpseo_set_canonical( $canonical ){
  16.  
  17.         if( is_front_page() && is_paged() ){
  18.             if( get_option( 'permalink_structure' ) ){
  19.                 $canonical  = trailingslashit( $canonical ) . 'page/' . get_query_var( 'page', 1 );
  20.             }
  21.             else{
  22.                 $canonical = add_query_arg( array(
  23.                     'paged' =>  get_query_var( 'page', 1 )
  24.                 ), $canonical );
  25.             }
  26.         }
  27.         return $canonical;
  28.     }
  29.     add_filter( 'wpseo_set_canonical', 'videotube_child_filter_wpseo_set_canonical', 10, 1 );
  30. }
Add Comment
Please, Sign In to add comment