WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have registration form code in my functions.php file like this

if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == 'registration') {
       $error = new WP_Error();
        if (empty(esc_attr($_POST['email'])))
            $error->add('regerror','Email is required.');
        if (!is_email(esc_attr($_POST['email'])))
            $error->add('regerror','Invalid email format.');

        if (email_exists(esc_attr($_POST['email'])))
            $error->add('regerror','Email already in use. Did you forget your Password? If yes click here to reset.');


Now can someone tell me how to display those error messages in my register page?


My registration page has code like this

<form method="post" action="<?php the_permalink(); ?>">
<!-- form fields goes here -->
<input name="action" type="hidden" value="registration" />
<input type="submit" id="submit" value="Register">
share|improve this question
That's it? Surely there is more code? This must be in a function right? Is it hooked to anything? Called directly? What? – s_ha_dum Feb 4 '13 at 5:16
@s_ha_dum Please check my update. Its not a function. My if loop checks the action parameter. If action == registration then the code will be executed. Its not hooked to anything. And yes I have some extra codes too in my if loop. I just trimmed it to make the question simple. – Giri Feb 4 '13 at 5:24
up vote 1 down vote accepted

With that in functions.php you'd probably have to declare $error to be global like so :

if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == 'registration') {
    global $error;
    $error = new WP_Error();
    // the rest of your code

And then do global $error; again on your registration page before trying to use it.

But I don't understand why you have that code in functions.php. That seems like bad design to me. You are running that if conditional every time any page loads and it sounds like you only need it on your registration page, which I am assuming is something you've written yourself and that you are not talking about the built in registration/login page at wp-login.php. Given that assumption, just move that code to the registration page and it will be available with no hassle. WP_Error has methods will let you get at the data.

share|improve this answer
Thankyou. I'll move the code to my register page as you advised.. – Giri Feb 4 '13 at 5:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.