Reputation: 625
I created shortcode in my child themes functions.php
file.
The shortcode
is as follows:
function add_login_form() {
if ( is_user_logged_in() )
{
echo 'Witaj zalogowany';
}
else
{
wp_login_form();
}
}
add_shortcode('login_form', 'add_login_form');
I added shortcode [login_form]
to my website (test area):
http://s540141209.domenaklienta.pl/wordpress/konto-klienta/
It is added to website after the text: "TUTAJ POWINIEN BYĆ LOGIN FORM LUB NAPIS „WITAJ ZALOGOWANY”!"
It should be inside first div: <div class="et_pb_row">
But it is shown just after the header of a page. Have you any idea why it happens that way?
Thansk in advance. But it happens to show before everything on website.
Upvotes: 4
Views: 269
Reputation: 1179
See http://codex.wordpress.org/Shortcode_API on how shortcodes acts. In a shortcode function you should always return the result of the processing done in the shortcode action. Echoing it outputs it as soon as the hook is executed, instead of being inserted in where it should be.
function add_login_form() {
if ( is_user_logged_in() )
{
return 'Witaj zalogowany';
}
else
{
return wp_login_form(array('echo'=>false));
}
}
add_shortcode('login_form', 'add_login_form');
For all arguments of wp_login_form, see http://codex.wordpress.org/Function_Reference/wp_login_form .
Upvotes: 6