• Hi

    I added a function to my child theme which is a modified version of this: https://codex.www.ads-software.com/Function_Reference/is_user_logged_in

    It adds a welcome message, avatar and various links to subscribers but a different view for non-subscribers. This works well and adds the message just below the page title of pages and posts. I have noticed though that its also adding this message to the RSS feed which breaks it and also to certain widgets (ones which show random posts or featured images).

    I am trying to figure out a way to remove it from widgets and the rss feed and just wondering if anyone has any ideas.

    Thanks

    add_action( 'loop_start', 'personal_message_when_logged_in' );
    
    function personal_message_when_logged_in() {
    
    if ( is_user_logged_in() ) :
    
    global $current_user;
    get_currentuserinfo();
        $current_user = wp_get_current_user();
    
        echo '<div class=welcome-mess><p style="text-align: center;">'; echo get_wp_user_avatar($current_user->ID, 96); echo 'Member: ' .'<strong>' . $current_user->user_login . '</strong>'. "<br>"; echo '<a href="https://www.dugswelcome.com/members/">News</a> | <a href="https://www.dugswelcome.com/your-dugs-profile/">Profile</a> | <a href="https://www.dugswelcome.com/postcodesearch/">Search</a> | <a href="https://www.dugswelcome.com/discount-codes/">Discounts</a> | <a href="https://www.dugswelcome.com/dogfriendly/dog-friendly-maps/">Maps</a> | <a href="https://www.dugswelcome.com/printable-pdf-guides/">Downloads</a> | <a href="https://www.dugswelcome.com/bookmarks/">Bookmarks</a></p><hr /></div>';
    
    else :
            echo '<div class=welcome-nonmembers><p style="text-align: right;"><a href="https://www.dugswelcome.com/dug-shop/">Online Shop</a> | <a href="https://www.dugswelcome.com/dugs-account-sign-up/">Membership</a> | <a href="https://www.dugswelcome.com/wp-login.php?action=lostpassword" rel="nofollow">Lost Password?</a></p><hr /></div>';
    
        endif;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter WordDug

    (@worddug)

    Moderator bcworkz

    (@bcworkz)

    You can use is_feed() to return from your function without doing anything. That takes care of feeds. I believe you can detect widget queries when is_main_query() is not true. If that doesn’t work, there should be something in the global $wp_query that would give a clue when widget queries are being run.

    Thread Starter WordDug

    (@worddug)

    I couldnt get the function to work by modifying it so I decided to disable the rss feeds and also add css to the sidebar (display:none;) to remove it from any widgets. Not ideal but works fine.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Welcome Message (is_user_logged_in)’ is closed to new replies.