Title: Nested Shortcodes
Last modified: August 24, 2016

---

# Nested Shortcodes

 *  [jwsmith300](https://wordpress.org/support/users/jwsmith300/)
 * (@jwsmith300)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/nested-shortcodes-6/)
 * I’m trying to nest
 * [groups_group_info group=”MD2015″ show=”users”]
 * inside
 * [upme group=HERE view=compact users_per_page=10]
 * where it says here.
 * I’ve been struggling with do_shortcode for hours and can’t for the life of me
   get anything to work.

Viewing 12 replies - 1 through 12 (of 12 total)

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/nested-shortcodes-6/#post-6070516)
 * Hi jwsmith300
 * From what plugins are the shortcodes? If they are from one plugin ask the plugin
   author if it can be done. You can’t nest them if from different plugin’s as the
   shortcodes are not aware of each others attributes.
 * You also can’t nest the way you want them to as they are self-closing shortcodes.
   
   [https://codex.wordpress.org/Shortcode_API#Enclosing_vs_self-closing_shortcodes](https://codex.wordpress.org/Shortcode_API#Enclosing_vs_self-closing_shortcodes)
 * This is how you would nest enclosing shortcodes
    [https://codex.wordpress.org/Shortcode_API#Nested_Shortcodes](https://codex.wordpress.org/Shortcode_API#Nested_Shortcodes).
 *  Thread Starter [jwsmith300](https://wordpress.org/support/users/jwsmith300/)
 * (@jwsmith300)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/nested-shortcodes-6/#post-6070518)
 * Yeh they are from different plugins
 * the first simply returns a list of numbers separated by commas.
 * the second is expecting a list of numbers separated by commas where I wrote HERE.
 * I just want it to get the list of numbers and use it as the attribute.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/nested-shortcodes-6/#post-6070522)
 * Can you post the code that doesn’t work. I assume you don’t use this in the post
   editor as you mentioned the do_shortcode function.
 *  Thread Starter [jwsmith300](https://wordpress.org/support/users/jwsmith300/)
 * (@jwsmith300)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/nested-shortcodes-6/#post-6070525)
 * [upme group=do_shortcode(‘[groups_group_info group=”MD2015″ show=”users”]’ ) 
   view=compact users_per_page=10]
 * The UPME plugin allows you to select a range of profiles to show based on a list
   of user IDs. I am trying to use the groups_group_info shortcode to return a list
   of User IDs to show.
 * Both shortcodes work okay when not nested.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/nested-shortcodes-6/#post-6070529)
 * Before we proceed do you put this in the post editor or in one of your theme 
   template files?
 * do_shortcode() is a php function and doesn’t work in the post editor. It’s either
   stripped from the content (as php is not allowed) or interpreted as text.
 * What are the plugins. Provide links to where you downloaded them from.
 *  Thread Starter [jwsmith300](https://wordpress.org/support/users/jwsmith300/)
 * (@jwsmith300)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/nested-shortcodes-6/#post-6070530)
 * in the post editor :/ so that is why it doesn’t work. I guess I code code it 
   into the upme group plugin but then I wouldn’t be able to change what group I
   was calling.
 * [https://wordpress.org/plugins/groups/](https://wordpress.org/plugins/groups/)
   
   [http://codecanyon.net/item/user-profiles-made-easy-wordpress-plugin/4109874](http://codecanyon.net/item/user-profiles-made-easy-wordpress-plugin/4109874)
 *  Thread Starter [jwsmith300](https://wordpress.org/support/users/jwsmith300/)
 * (@jwsmith300)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/nested-shortcodes-6/#post-6070534)
 * Can you code it anyway so that it retrieves the list of IDs first. Calls this
   phrase X
 * and then it runs the second shortcode and uses X as the attribute?
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/nested-shortcodes-6/#post-6070537)
 * Try it with this [untested]:
 *     ```
       [upme group='[groups_group_info group="MD2015" show="users"]' view="compact" users_per_page="10"]
       ```
   
 * I don’t think that will work, but why not try.
 * It’s difficult because the user profiles plugin is a commercial plugin. I can’t
   see in the code.
 * You can filter a shortcode if the plugin uses this function and provides the 
   third parameter. [https://codex.wordpress.org/Function_Reference/shortcode_atts](https://codex.wordpress.org/Function_Reference/shortcode_atts)
 * Can you put this in your theme’s functions.php file for testing:
 *     ```
       add_filter ( 'shortcode_atts_upme', 'my_shortcode_atts', 10, 3  );
   
       function my_shortcode_atts( $out, $pairs, $atts ) {
       	echo '<pre>';
       	print_r( $out );
       	echo '</pre>';
   
       	return $out;
       }
       ```
   
 * Create a test post with the upme shortcode.
    If the filter is used it will print
   an array with atrributes to the screen when on the post’s page in the front end
   of your site.
 * Remove the shortcode and code after testing.
 *  Thread Starter [jwsmith300](https://wordpress.org/support/users/jwsmith300/)
 * (@jwsmith300)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/nested-shortcodes-6/#post-6070539)
 * You mean just add [upme] and see what it does after adding that code in the functions
   file?
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/nested-shortcodes-6/#post-6070550)
 * Yes. Or use it with some of the attributes. It should print the array regardless
   of the attributes on the single post page.
 *  Thread Starter [jwsmith300](https://wordpress.org/support/users/jwsmith300/)
 * (@jwsmith300)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/nested-shortcodes-6/#post-6070559)
 * it just displays the user who is logged in profile as no group attribute is specified
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/nested-shortcodes-6/#post-6070643)
 * It doesn’t seem the upme shortcode uses the shortcode_atts() function.
    Remove
   the testing code from your functions.php
 * Another way is to create your own shortcode with the attributes from both the
   groups_group_info and upme shortcode combined.
 * Try it with this in your functions.php file:
 *     ```
       function upme_group_shortcode( $atts ) {
   
       	$args = shortcode_atts( array(
       			// defaults
       			'group'          => '',
       			'show'           => 'users',
       			'view'           => 'compact',
       			'users_per_page' => 10,
       		), $atts, 'upme_group' );
   
       	// check if a group was provided
       	if ( empty( $args['group'] ) ) {
       		return '';
       	}
   
       	// get the group with the groups_group_info shortcode
       	$group_info = "[groups_group_info group='{$args['group']}' show='{$args['show']}']";
       	$group = do_shortcode( $group_info );
   
       	// check if a group was found
       	if ( empty( $group ) ) {
       		return '';
       	}
   
       	$upme_shortcode = "[upme group='{$group}' view='{$args['view']}'";
       	$upme_shortcode .= " users_per_page='{$args['users_per_page']}']";
   
       	// return the upme shortcode
       	return do_shortcode( $upme_shortcode );
       }
   
       // create a new shortcode 'upme_group'
       add_shortcode( 'upme_group', 'upme_group_shortcode' );
       ```
   
 * Now you can use the new ‘upme_group’ shortcode like this:
 *     ```
       [upme_group group="MD2015" show="users" view="compact" users_per_page="10"]
       ```
   
 * This code is untested as I don’t have access to the
    User Profiles shortcode.

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Nested Shortcodes’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 12 replies
 * 2 participants
 * Last reply from: [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/nested-shortcodes-6/#post-6070643)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
