LSCache + ESI Enabled Shortcode
-
Hi there,
I created a shortcode with the help of OpenAI to display the avatar(custom user meta) of author. The shortcode is working but not as expected when ESI is enabled. It always returns with the fallback image instead of the author avatar. However, the shortcode works fine when I use it without ESI.
For example:
Working as expected: [current_author_avatar]
Not working as expected: [esi current_author_avatar ttl=”60″]How to fix this issue?
Code I am using:
function current_author_avatar_shortcode() { if ( is_author() ) { $user_id = get_queried_object_id(); // Gets the author ID for author archives } else { $user_id = get_the_author_meta('ID'); // Gets the author ID for single post pages } $user = get_user_by( 'id', $user_id ); $first_name = $user->first_name; $last_name = $user->last_name; $avatar_url = get_user_meta($user_id, 'user_avatar', true); if (empty($avatar_url)) { $avatar_url = 'https://static.domain.net/data/static-media/system-default/avatar.png'; } $output = '<div class="user-avatar-con"><img class="user-avatar" src="' . $avatar_url . '" alt="' . $first_name . ' ' . $last_name . '"></div>'; return $output; } add_shortcode('current_author_avatar', 'current_author_avatar_shortcode');
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘LSCache + ESI Enabled Shortcode’ is closed to new replies.