I want to check at page load if the user is logged in or not and hide the login mask I programmed accordingly. There is a reason I'm using said login mask instead of redirecting to the WordPress standard login.
The idea was to use functions.php:
if ( is_user_logged_in() ) {
echo '<li id="text-2" style="display:none;">';
} else {
echo '<li id="text-2">'; }
This code works, but my page kind of stops loading after that. And if I pack the entire thing into a function I get an error - Parse error has been resolved by Answer01 by Brad Dalton.
Long story short: How do I show/hide certain elements depending on whether a user is logged in or not?
edit01: Here's the parts before the code I posted above:
<?php
function modify_user_contact_methods($user_contact) {
// Add new fields
$user_contact['uidnumber'] = 'UID-Nummer';
return $user_contact;
}
add_filter('user_contactmethods', 'modify_user_contact_methods');
?>
<?php
if ( is_user_logged_in() ) {
echo '<li id="text-2" style="display:none;">';
} else {
echo '<li id="text-2">';
}
?>
edit02: I've tried using the code provided below with the action_hook:
add_action( 'loop_start', 'loginCheck' );
function loginCheck() {
if ( is_user_logged_in() ) {
echo '<li id="text-2" class="hidden">';
} else {
echo '<li id="text-2">';
}
}
Yet now the page looks like this: - solved in edit03
edit03: I've used a temporary work-around by switching loop_start with loop_end. However as I said earlier, the section I want to hide is still being displayed.
edit04: WP_DEBUG.. let's see.. - no relevant finding related to the problem
edit05: So here's the summary of the current situation:
- Page is loading, all elements are displayed, check.
- jQuery opens and closes the Login-Box if the user is not logged in, check.
- Content is hidden when user is logged in to prevent confusion, UNSOLVED.
So essentially it's only the function that doesn't do what it's supposed to.
Here's a link to the website: easy2work.at
What I want is to hide the "Firmen-Login | Anmelden" once the user is logged in and display something else up there which is ready to be implemented.
I want to check at page load if the user is logged in or not and hide the login mask I programmed accordingly. There is a reason I'm using said login mask instead of redirecting to the WordPress standard login.
The idea was to use functions.php:
if ( is_user_logged_in() ) {
echo '<li id="text-2" style="display:none;">';
} else {
echo '<li id="text-2">'; }
This code works, but my page kind of stops loading after that. And if I pack the entire thing into a function I get an error - Parse error has been resolved by Answer01 by Brad Dalton.
Long story short: How do I show/hide certain elements depending on whether a user is logged in or not?
edit01: Here's the parts before the code I posted above:
<?php
function modify_user_contact_methods($user_contact) {
// Add new fields
$user_contact['uidnumber'] = 'UID-Nummer';
return $user_contact;
}
add_filter('user_contactmethods', 'modify_user_contact_methods');
?>
<?php
if ( is_user_logged_in() ) {
echo '<li id="text-2" style="display:none;">';
} else {
echo '<li id="text-2">';
}
?>
edit02: I've tried using the code provided below with the action_hook:
add_action( 'loop_start', 'loginCheck' );
function loginCheck() {
if ( is_user_logged_in() ) {
echo '<li id="text-2" class="hidden">';
} else {
echo '<li id="text-2">';
}
}
Yet now the page looks like this: - solved in edit03
edit03: I've used a temporary work-around by switching loop_start with loop_end. However as I said earlier, the section I want to hide is still being displayed.
edit04: WP_DEBUG.. let's see.. - no relevant finding related to the problem
edit05: So here's the summary of the current situation:
- Page is loading, all elements are displayed, check.
- jQuery opens and closes the Login-Box if the user is not logged in, check.
- Content is hidden when user is logged in to prevent confusion, UNSOLVED.
So essentially it's only the function that doesn't do what it's supposed to.
Here's a link to the website: easy2work.at
What I want is to hide the "Firmen-Login | Anmelden" once the user is logged in and display something else up there which is ready to be implemented.
Share Improve this question edited Jul 27, 2015 at 10:25 theHubi asked Jul 27, 2015 at 8:45 theHubitheHubi 892 gold badges4 silver badges14 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 2Your code won't work in a themes functions file unless it includes a hook.
Try something like:
add_action( 'loop_start', 'your_function' );
function your_function() {
if ( is_user_logged_in() ) {
echo '<li id="text-2" class="hide">';
} else {
echo '<li id="text-2">';
}}
WP_DEBUG
totrue
to see what's the inner problem resides there after. – Mayeenul Islam Commented Jul 27, 2015 at 9:31