
  add_filter('request', function(array $query_vars) {
    // do nothing in wp-admin
    if(is_admin()) {
        return $query_vars;
    }
    // check if the query is for a category archive
    if(isset($query_vars['category_name']) && !isset($query_vars['name'])) {
      	
      //generate the page path
        $pagename = 'category/' . $query_vars['category_name'];
		
      //attempt to load the page matching the $pagename slug
		$page = get_page_by_path( $pagename , OBJECT );

     if ( isset($page) ){
        // completely replace the query with a page query
        $query_vars = array('pagename' => "$pagename");
	 }
    }
    return $query_vars;
});