How to Hide Header-Text when Logged in?

  • Paul
    Paul
    Newbie 36 points
    August 13, 2015 at 3:44 pm

    Dear community

    for my directory website I used the Header Text section (page setup -> general layout) to insert a text stating “Not Member yet? Register” where the word “Register” is a link (see img1).
    However, when a user is already a member it doesn’t make sense to ask this question. Therefore, I would like to hide this text when someone is logged in. Unfortunately it seems that the section where I entered the text does not accept php (img2). Any suggestions?

    Attachments:
    You must be logged in to view attached files.
  • Hemanta Chakladar
    Hemanta Chakladar
    Super Guru 1,710 points
    August 13, 2015 at 4:39 pm

    wrap div.class and hide it. Do this, in your text…

    <div class="header-txt">your_code_here</div>

    and add this code in the Design Setting > Custom meta data > wp_footer box

    <script>
    jQuery(".logged-in .header-txt").remove();
    </script>

  • Josh
    Super Guru 13,875 points
    August 13, 2015 at 5:33 pm

    Hello Paul,
    Why not simply translate the text ‘Register’ to ‘Not Member yet? Register’ under Language Setup >6.Header instead of adding another link?

  • Paul
    Paul
    Newbie 36 points
    August 13, 2015 at 9:30 pm

    Thank you so much Hemanta, it worked! Just one little thing: now every time a logged-in user loads a new page the text pops up again for the blink of an eye and than disappears. Is there a way to fix this?

  • Hemanta Chakladar
    Hemanta Chakladar
    Super Guru 1,710 points
    August 14, 2015 at 6:23 am

    Use this in , Design > Custom Meta > wp_head

    <style>
    .logged-in .header-txt { display:none; }
    </style>
    This reply was awarded the best answer by the topic poster.
  • Paul
    Paul
    Newbie 36 points
    August 14, 2015 at 9:05 am

    Great! Now it works perfectly. Thank you so much 🙂

  • Hemanta Chakladar
    Hemanta Chakladar
    Super Guru 1,710 points
    August 14, 2015 at 9:17 am

    Welcome 🙂

  • Paul
    Paul
    Newbie 36 points
    August 14, 2015 at 11:17 am

    One more thing: Is there also a function for NOT logged in?
    So that an object would be displayed instead of removed when a user is logged?

  • Paul
    Paul
    Newbie 36 points
    August 14, 2015 at 12:09 pm

    figured it out. played around with your code a little bit. you can just replace “remove” with “show”

    jQuery(“.logged-in .header-txt”).show();

  • Hemanta Chakladar
    Hemanta Chakladar
    Super Guru 1,710 points
    August 14, 2015 at 12:18 pm

    Great, and add style="display:none;"in html, so that it won’t show for `non-logged in user.

    like, <div class="header-txt" style="display:none;">your_code_here</div>

Viewing 10 posts - 1 through 10 (of 10 total)

New Business Themes for WordPress 2020

Start your new website today!

View Business Themes