When I try to add the following code to functions.php I keep getting errors (site goes down, seeming to indicate a php error). I've stared at this code forever and can't seem to figure out why it should give an error when it's added to functions.php.

Any suggestions for what I should change? Thanks!

function hide_prompt() {
   if(is_user_logged_in()) {
    echo '
    <style> .app { display: none!important; } </style>   
add_action('wp_footer', 'hide_prompt');
  • from config file set WP_DEBUG true, refresh and check if you see any php error – Sangita Kendre Sep 13 at 6:00
  • I have checked this above code into website and it's working perfect. so I think there is no issue with code. may be possible other coding issue for getting errors. – Tanmay Patel Sep 13 at 6:21
  • You might have a plugin or your theme defining a function called hide_prompt - try changing the name of the function to something unique, eg vanessa_hide_prompt. – Peter HvD Sep 13 at 9:54
  • 1
    The original code in your question (the one in the text box for editing the question) contains invisible characters which result in "unexpected echo" error - and if you copy the rendered code on this page (not in the text box), then your code should work fine. So be extra careful when copying/pasting code. – Sally CJ Sep 14 at 1:19
  • Thanks for the tips. Peter, I tried a number of different names and it still errors. Sally, how did you tell there were invisible characters? (I assume you mean beyond spaces and tabs?) – Vanessa Harris Sep 14 at 1:53

You are using the wrong hook, and you are doing it the wrong way. Sorry to be clear.

Adding stylesheet to the footer is no good style at all and rather a beginner mistake. Have a look at loading scripts correctly.

You need to add that stylerule the to html-head of your login page/hook.

Since you want to edit the login form, the correct hook, which you need to use is login_head

See Codex: Login Hooks

Also see: Login Head

something like this (functions.php):

function se_css_output_hide_promt() { ?>
    <style type="text/css" id="se-answer-customized-css">
        //switch to php to check the login status, add css when true
        if(is_user_logged_in()): ?>

        .app { display: none!important; }

        <?php endif; ?>
<?php }
add_action('login_head', 'se_css_output_hide_promt');

I bet !important is no longer needed in case you are doing it this way. This css will be added right before the ending html-head, very close to your html. Meaning that your !important is propably no longer necessary.

  • Thanks, Is endif; required in php?, also, I haven't seen the : used before, is there a difference between the syntax I had and using the : Thanks again. – Vanessa Harris Sep 14 at 1:53
  • The double quotes mean that the If Statement stays Open, Thema endif ist required – user3135691 Sep 15 at 16:22

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.