Jacob Thank you for the quick reply. I checked the documentation and found that the is_user_logged_in() is a pluggable function. I think this is the reason i was getting the error.
I used is_user_logged_in()
function with init action hook
and it works.
function example_function() {
if ( is_user_logged_in() ) {
echo 'Welcome, user!';
}
}
add_action('init', 'example_function');