How to make my logged-in user-role shortcode displaying name instead of slug?

Based on what you wrote, you should use instead : if ( ! is_admin() ) { function get_user_role() { global $wp_roles; $user = wp_get_current_user(); $roles = ( array ) $user->roles; foreach ( $roles as $role ) { $user_role=”<p>” . $wp_roles->roles[ $role ][‘name’] . ‘</p>’; } return $user_role; } add_shortcode( ‘display_user_role’, ‘get_user_role’ ); } It works … Read more

shortcode appears as text in the search result

There is a stray > at the end of our code above, make sure that is a ?> instead of > Try another shortcode, something simple to verify it is not shortcodes in general. Clear you caching, clear permalinks by going to the permalinks page and clicking update. Check if the search plugin has caching … Read more

Nav Menu Short code Not working When non Login

The issue you’re facing, where the shortcode appears as text instead of being executed for users who are not logged in, could be due to the timing of when the do_shortcode function is applied to the menu items. The wp_nav_menu filter is not the ideal place to apply do_shortcode, as it can lead to unexpected … Read more