Shortcode not working as expected with CNC
-
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 I use the shortcode inside the CNC(Content No Cache) and the CNC shortcode on the post page. It always returns with the fallback image instead of the author avatar. However, the shortcode works fine when I use the original shortcode directly on the post page.
For example:
Working as expected: [current_author_avatar]
Not working as expected: [content_no_cache id=”5187″]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');
- The topic ‘Shortcode not working as expected with CNC’ is closed to new replies.