How to display some selected user meta data on a specific page with a shortcode?

Here is the simplest shortcode that will do the job for you add_shortcode(‘USER_META’, ‘user_meta_shortcode_handler’); /** * User Meta Shortcode handler * usage: [USER_META user_id=1 meta=”first_name”] * @param array $atts * @param string $content * @return stirng */ function user_meta_shortcode_handler($atts,$content=null){ return esc_html(get_user_meta($atts[‘user_id’], $atts[‘meta’], true)); } USAGE: [USER_META user_id=1 meta=”first_name”] [USER_META user_id=1 meta=”last_name”]

append stylesheet via shortcode

here is a handy function i use a lot which is based on the_posts hook function check_for_shortcode($posts) { if ( empty($posts) ) return $posts; $flag = false; foreach ($posts as $post) { if ( stripos($post->post_content, ‘[YOUR_SHORTCODE_HERE’) ) $flag = true; break; } if ($flag){ //add scripts and styles here eg: //wp_enqueue_script //wp_enqueue_style } return $posts; … Read more

Shortcodes not resolved in AJAX call response

Since version 4.9 visual composer added shortcode lazy loading. To use VC shortcodes on AJAX content use this function before printing the content WPBMap::addAllMappedShortcodes();. So below code may help you, function get_page_content(){ $id = $_REQUEST[‘id’]; $page_data = get_page($id); WPBMap::addAllMappedShortcodes(); echo apply_filters(‘the_content’, $page_data->post_content); wp_die(); } add_action( ‘wp_ajax_nopriv_get_page_content’, ‘get_page_content’ ); add_action( ‘wp_ajax_get_page_content’, ‘get_page_content’ );

Execute shortcode only in another shortcode

To use a different callback for the nested headings switch the shortcode handler in the pricing_box callback and restore the main handler before you return the string. add_shortcode( ‘pricing_box’, ‘shortcode_pricing_box’ ); add_shortcode( ‘heading’, ‘shortcode_heading_main’ ); function shortcode_pricing_box( $atts, $content=”” ) { // switch shortcode handlers add_shortcode( ‘heading’, ‘shortcode_heading_pricing_box’ ); $out=”<div class=”pricing-box”>” . do_shortcode( $content ) … Read more