cache – Get user name and caching system

Question

I am trying to get user name by this function and shortcode

function custom_shortcode_func() {
    ob_start();
    $current_user = wp_get_current_user();
    echo 'Welcome ' . $current_user->display_name . '<br />';
    $output = ob_get_clean();
    return $output;
}
add_shortcode('current_user', 'custom_shortcode_func');

Then I use shortcode in my header and its working fine. But the problem is that I am using caching module and if user load website logged out first and then log in this shortcode is not working because of caching system. If I disable it its working perfect. How can I fix that ?

0
Samuel Marcinko 6 months 2022-02-12T09:13:43-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse