Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator threadi

    (@threadi)

    This should work reliably without any caching plugins. Have you tried it like this?

    However, one problem could be ob_start(). I would rather write the code like this:

    function custom_shortcode_func() {
    if ( is_user_logged_in() ) {
    $current_user = wp_get_current_user();
    return esc_html( $current_user->display_name );
    }
    return 'Not logged in';
    }
    add_shortcode('current_user', 'custom_shortcode_func');

    In this way, it also complies with WordPress coding standards.

    Thread Starter michaeljgibson

    (@michaeljgibson)

    Hi threadi, Thank you for the fast response. Unfortunately, your suggestion does not work for me on the Bluehost test website. However I tried a simple local install with the same setup and it appears to work just fine in that case. So I am now assuming Bluehost is the problem and will try another hosting platform.

    Thread Starter michaeljgibson

    (@michaeljgibson)

    Just a follow up on this, I tried the same test on IONOS, and it worked just fine. So, I have to say the problem is with Bluehost, but unfortunately, I cant say anything more specific than that.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Problem with shortcode to show user name – requires page refresh to work’ is closed to new replies.