WordPress.org

Ready to get started?Download WordPress

Forums

Nice Search
Added Missing Pagination(Have a similar Plugin) (1 post)

  1. Bruno Sacco
    Member
    Posted 3 years ago #

    Added pagination, and a PERM redirect to avoid SEO problems.
    Also removed the "+" from URL too.

    function cws_nice_search_redirect() {
    
    	if ( is_search() && strpos( $_SERVER['REQUEST_URI'], '/wp-admin/' ) === false && strpos( $_SERVER['REQUEST_URI'], '/search/' ) === false ) {
    
    		$clean = str_replace( array( '+',' ', '%20' ),  array( '-', '-', '-' ), get_query_var( 's' ) );
    		if(strpos( $_SERVER['REQUEST_URI'], '/page/' ) === false)
    		{
    			wp_redirect( home_url( '/search/' . $clean ), 301 );
    			exit();
    		}
    		else
    		{
    			wp_redirect( home_url( '/search/' . $clean ."/page/" . get_query_var( 'paged' ) ), 301 );
    			exit();
    		}
    	}
    }

    Thanks, nice job.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic