In wordpress I am manipulation 404 response. I want to give the response before 404 error is given to google

May be the question in title is not explaining what exactly I want. So I will explain one logic and then ask what problem I am getting from that.

We are using wordpress. We have 2 categories Option1(Having 64 different values) and Option2(Having 8 different values). We wanted url like ourdomain/Option1/Option2 depending on users location. And data on that url will be specific according to that Option1 and Option2. We dont wanted all this 64*8 actual wordpress pages to be created.

So after searching much on net we had one solution that I implemented one plugin for routing.

IN that code snippet was as follow.

function site_router() {

global $route,$wp_query,$window_title;
error_reporting(E_ALL);
if ( $wp_query->is_404 ) 
    {
        $wp_query->is_404 = false;
        $cUrl="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
        $targetUrl="";
        switch($cUrl)
                {
                /* According to condition  I had written diffent cases like below.
                */
        default :
            {           
            include(get_template_directory() . "/home.php" ); 
            $template =locate_template('pagepath/home.php');
                        $window_title = 'dynamically it will come';
                        if ($template) {
                        load_template($template);
                        die;
                        }
                    }                   

                }
         }
}

add_action( 'wp', 'site_router');

So by this my purpose was fulfilled successfully.

But now problem is that google is saying they are getting back a 404 error. I think obviosly it will give as after it gives the error we are doing all template loading and all stuff.

So Can any body guide me how can I do this before that 404 response is given to google.

Solutions

WordPress has a function to send a different status header:

status_header( 200 );

If you send that after WordPress has send its headers and before you print anything you will get a status header 200.

You could also filter 'status_header' and change the value there. See wp-includes/functions.php for details.

Similar questions

Wordpress display name string manipulation
I have set the display name to show both first name and last name using the function below. How do I manipulate the LAST NAME to only pull the first letter of that string? Example, if you sign up as John Doe (First name= John, Last name= Doe), I want your display name to be John D. Thanks
Wordpress Theme manipulation - Remove Widget Background
So I know this is a bit out of ordinary for me to ask a question like this, but for some reason I am just really having an issue grasping this. My Problem: I have a responsive layout theme for word press, its clean its pretty. When implementing Google ad-sense into a text/html widget on the right bar it over runs the widget size and over hangs on t...
How to wrap Wordpress wpautop in a container with a class for CSS manipulation
I have a shortcode that queries through Worpress posts by category name and displays them on the front end. If there are no posts in that category, the user can write a "no posts available" message. The wpautop wraps the message with <p>...</p>. I want to style this <p>. I can't simply just add CSS to the paragraph tag obviously. ...
Permlink with anchor working with FF but not with Chrome (Wordpress and browser history manipulation involved)
The problem: In a WordPress site, using jQuery, there is a link with an anchor like so: When clicked via Firefox, it works: the url changes and the page scrolls to the anchor. When clicked via Chrome or Safari it does NOT work: the url changes, no access to the anchor. The new page has an ajax filter, so it loads the data according to the parameter...
Pause plugin option page until all data manipulation is complete
I have an option on my plugin page where I load content into all the posts in the blog. Now this takes some time, esp when there are a log of posts. Now the way is it set up now, when you press submit, the form success page is already presented, but you can see that the browser is still working. How can I have the plugin wait until the whole loop i...
wp_user_roles and Advanced Manipulation
I removed a line from my wp_user_roles to manually remove a role I had created and now the sites administration gives me an "You do not have sufficient permissions to access this page." error. I cannot get in and don't know how to fix what was inside. I've tried pasting in the default user roles in wp_user_roles: but still get the error for my admi...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy .