This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Add to Shortcode Generator

  • Creator
    Topic
  • #24071
    mizzinc
    Participant

    Hey Jason,

    Do you have any documentation on how to add a shortcode to the shortcode generator?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Author
    Replies
  • #24075
    Jason Bobich
    Keymaster

    Hi,

    No, it’s not something I’ve really intended anyone to add to. It’s honestly sort of a complex thing. In theory though you could probably add a basic shortcode to it…. ha, no promises though.

    Filter in a tab for it:

    https://github.com/themeblvd/theme-blvd-shortcodes/blob/master/includes/admin/generator/class-tb-shortcode-generator.php#L592

    And then filter in the shortcode and options to the big array of shortcodes:

    https://github.com/themeblvd/theme-blvd-shortcodes/blob/master/includes/admin/generator/class-tb-shortcode-generator.php#L2914

    The key of the array item you add to the larger array you’re filtering will be the shortcode like:

    $options['foo'] = array(
         // your basic array of options like other places in the 
         // framework, option types are more limited though
    );

    If you want your shortcode to enclose content like [foo]some content...[/foo], then within the shortcode’s options, create a textarea option with ID sc_content and I think the shortcode generator takes care of the rest.

    • This reply was modified 5 years, 3 months ago by Jason Bobich.
    #24082
    mizzinc
    Participant

    That was super helpful! I added the icon box with a few adjustments.

    The only bug: when opening the generator the icon box (new item) is set to active and looking at the source code it appears the Button is as well. Any thoughts?

    Button
    Icon Box Product								

    – Michael

    #24083
    Jason Bobich
    Keymaster

    What’s the code you’ve written for adding to the generator?

    #24084
    mizzinc
    Participant
    function my_shortcodes_groups( $groups ) {
    	$groups['icon_box_product']['id'] 		= 'product_box';
    	$groups['icon_box_product']['name'] 	= __( 'Icon Box Product', 'theme-blvd-shortcodes' );
    	$groups['icon_box_product']['sub'] 		= array();
    	return $groups;
    }
    add_filter( 'themeblvd_shortcodes_groups', 'my_shortcodes_groups' );
    function my_shortcodes_options( $options ) {
    	
    	// Image
    	$options['product_box']['image']['id'] 		= 'image'; 
    	$options['product_box']['image']['name'] 	=  __( 'Image URL', 'theme-blvd-shortcodes');
    	$options['product_box']['image']['desc'] 	= __( 'Copy/Paste the image/icon to be used. Ex: http://yoursite.com/image.jpg', 'theme-blvd-shortcodes');
    	$options['product_box']['image']['type']	= 'text'; 
    	
    	// Size
    	$options['product_box']['size']['id'] 		= 'size'; 
    	$options['product_box']['size']['name'] 	=  __( 'Icon Size', 'theme-blvd-shortcodes');
    	$options['product_box']['size']['desc'] 	= __( 'Enter a size for the icon - 16px to 128px', 'theme-blvd-shortcodes');
    	$options['product_box']['size']['type']		= 'text'; 
    	
    	// Location
    	$options['product_box']['location']['id'] 		= 'location'; 
    	$options['product_box']['location']['name'] 	=  __( 'Icon Placement', 'theme-blvd-layout-builder' );
    	$options['product_box']['location']['desc'] 	= __( 'Select how the icon should be displayed within the block.', 'theme-blvd-shortcodes');
    	$options['product_box']['location']['std']		= 'above';
    	$options['product_box']['location']['type']		= 'select';
    	
    		$options['product_box']['location']['options']['above']		= __('Icon is above title and content.', 'theme-blvd-shortcodes');
    		$options['product_box']['location']['options']['side']		= __('Icon is to the left of title and content.', 'theme-blvd-shortcodes');
    		$options['product_box']['location']['options']['side-alt']	= __('Icon is to the right of title and content.', 'theme-blvd-shortcodes');
    		
    	// Title
    	$options['product_box']['title']['id'] 		= 'title'; 
    	$options['product_box']['title']['name'] 	=  __( 'Title', 'theme-blvd-shortcodes');
    	$options['product_box']['title']['desc'] 	= __( 'Add the title', 'theme-blvd-shortcodes');
    	$options['product_box']['title']['type']	= 'text';
    	
    	// Text
    	$options['product_box']['text']['id'] 		= 'sc_content'; 
    	$options['product_box']['text']['name'] 	=  __( 'Content (optional)', 'theme-blvd-shortcodes');
    	$options['product_box']['text']['desc'] 	= __( 'Add content that will appear when mouse hovers over the product.', 'theme-blvd-shortcodes');
    	$options['product_box']['text']['std']		= 'Content here...';
    	$options['product_box']['text']['type']		= 'textarea';
    	
    	// Link URL
    	$options['product_box']['link_url']['id'] 		= 'link_url'; 
    	$options['product_box']['link_url']['name'] 	=  __( 'Link URL', 'theme-blvd-shortcodes');
    	$options['product_box']['link_url']['desc'] 	= __( 'Enter the full URL where you want this link to go to.', 'theme-blvd-shortcodes');
    	$options['product_box']['link_url']['type']		= 'text';
    	
    	// Background Colour
    	$options['product_box']['bg_color']['id'] 		= 'bg_color'; 
    	$options['product_box']['bg_color']['name'] 	=  __( 'Product', 'theme-blvd-shortcodes');
    	$options['product_box']['bg_color']['desc'] 	= __( 'Please select the product which will automatically apply the background gradient colour', 'theme-blvd-shortcodes');
    	$options['product_box']['location']['std']		= 'hydrocolloids';
    	$options['product_box']['bg_color']['type']		= 'select';	 
    	
    		$options['product_box']['bg_color']['options']['hydrocolloids']		= __('Hydrocolloids', 'theme-blvd-shortcodes');
    		$options['product_box']['bg_color']['options']['colours']			= __('Colours', 'theme-blvd-shortcodes');
    		$options['product_box']['bg_color']['options']['emulsifiers']		= __('Emulsifiers', 'theme-blvd-shortcodes');
    		$options['product_box']['bg_color']['options']['flavourings']		= __('Flavourings', 'theme-blvd-shortcodes');
    		$options['product_box']['bg_color']['options']['fortificants']		= __('Fortificants', 'theme-blvd-shortcodes');
    		$options['product_box']['bg_color']['options']['andmore']			= __('And more....', 'theme-blvd-shortcodes');
    		$options['product_box']['bg_color']['options']['andmore']			= __('None', 'theme-blvd-shortcodes');
    				
    	return $options;
    	
    }
    add_filter( 'themeblvd_shortcodes_options', 'my_shortcodes_options' );
    #24095
    Jason Bobich
    Keymaster

    When you filter themeblvd_shortcodes_groups you’re making the key of the array item you’re adding icon_box_product — but instead the keys of these arrays need to be integers that are incremented.

    So, do it like this:

    function my_shortcodes_groups( $groups ) {
    
        $groups[] = array(
            'id'    => 'product_box',
            'name'  => __( 'Icon Box Product', 'theme-blvd-shortcodes' ),
            'sub'   => array()
        );
    
        return $groups;
    }
    add_filter( 'themeblvd_shortcodes_groups', 'my_shortcodes_groups' );
    #24099
    mizzinc
    Participant

    I’ll just go find that coding 101 book I had. Ha! Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.