I am using Code Snippets plugins, that allow create shortcodes from the Wordpress Admin panel. I am using a simple shortcode to print some info and works great. Anyway, I want make this add some info if the parameter 'error' is in the url.

To make this, I am doing this:

add_shortcode( 'my_shortcode', function () {

    $out = '';

    print_r($_GET); //--> prints Array ( )
        $out .='<div id="login_error">El usuario o contraseña no es correcto.</div>';   

    $out .='HTML info';

    return $out;
} );

Anyway, my URL is http://localhost/login/?error=true and I think this should be working. Some idea about this problem?


$_GET is a glob var. which is triger/created when you're sending html form data og visit a link. When is send from form you can add the needet info in "action" atr. But from youre example i see onlu that you return from the function some string...did not see the part of adding it to the $_GET...

as sugested up you can use $_REQUEST["GET"] or $_SERVER['REQUEST_METHOD'] allso

lets roll back a sec. - you need to add some extra data to the get requst if have some specific condition ( 'error )and the what??? for example :

This directly will add data to url and redirect to da location, do proper escaping..this is example

function get_server_info(){

$server = array();
 $server["ip"] = $_SERVER['REMOTE_ADDR'];
}else{ $server["ip"] = false; }

 $server["host"] = $_SERVER['HTTP_HOST'];
}else{ $server["host"] = false; }

 $server["query"] = $_SERVER['QUERY_STRING'];
}else{ $server["query"] = false; }

 $server["from"] = $_SERVER['HTTP_REFERER']; 
}else{ $server["from"] = false; }

  $server["requested"] = $_SERVER["REQUEST_URI"];
}else{ $server["requested"] = false; }

return $server;


function redirect_to($location,$content = "text/html"){

header("Location: ".$location);
header("Content-Type: ".$content);


this should redirect you to the original intendet location whit extra url data somthing like this

function add_to_url(){

$server = get_server_info();

if( youre condition ){

    $to_add ='<div id="login_error">El usuario o contraseña no es correcto. 

    $redirect_to =  $server["requested"]."&".$to_add;

    redirect_to( $redirect_to);



  • You could see that in the bottom of the question I leave the url with the GET parameter filled :) – user1422434 Apr 10 '20 at 16:44

reading about this type of problems (because my template wasn't the problem) and it's a fresh installation. I read that wordpress recommends the use of $_REQUEST instead $_GET (Anyway I see that other people can use $_GET without problems) and tried with $_REQUEST, now it's working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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