WordPress.org

Ready to get started?Download WordPress

Plugin Directory

Shortcodes Generator

A plugin to generate shortcodes and a corresponding button in the WordPress visual editor. Wicked!

So how do I add the shortcodes, anyway?

Well, after you've moved the shortcodes folder to your theme, open up

shortcodes/array.php

. The simplest one you can make would look like this:

$shortcodes['button'] = array(
    'shortcode' => 'button'
);

That would create a shortcode that looks like this: [button]

Then, for every shortcode you wish to add, just repeat

$shortcodes['shortcode']

with the details filled in!

The template is as follows:

$shortcodes['name'] = array(
    'shortcode' => '',
    'function' => '',
    'tag'   => '',
    'selectable' => 0
    'atts' => array(
        'name', 'name2'
    ),
    'children'=> array(
        'child' => array(
            'shortcode' => '',
            'function' => '',
            'tag'   => '',
            'selectable' => 0
            'atts' => array(
                  'name', 'name2'
            ),
        ),
    )
);

This seems too simple. What if I want more control?

To use a specific function along with the short code, all you have to do is pass

'function' => 'function_name'

as one of the paramaters for the array. Here's an example:

$shortcodes['button'] = array(
    'shortcode' => 'button',
    'function' => 'cur_button_shortcode',
    'selectable' => 1
    'atts' => array(
        'class', 'color'
    ),
);

The shortcode will now use cur_button_shortcode as the function to run for the shortcode. The shortcode will look like this:

[button class="" color""][/button]

If you want to define some default parameters, just change atts to this:

'atts' => array(
    'class' => 'small',
    'color' => 'green'
)

It will produce this output:

[button class="small" color"green"][/button]

Want to be able to select text and have the shortcode wrap around it? Just pass

'selectable' => 1

.

I will eventually add a ThickBox dialogue so that people can have default selections picked out for them, and actually have more of a UI. But this will do for now.

Is it possible to embed into themes?

Sure is! To do that, move the plugin file into your theme and include this code in your functions.php file:

add_action( 'after_setup_theme', 'cur_shortcodes_theme_setup');
function cur_shortcodes_theme_setup(){
    // We're assuming the plugin directory is located in
    // /wp-content/themes/themename/shortcodes-generator/
    define( 'CSG_URI', get_template_directory_uri() . '/shortcodes-generator/' );
    require_once 'shortcodes-generator/cur-shortcodes-generator.php';
    $csg = Cur_Shortcodes_Generator::get_instance();
}

It'll take care of the rest!

Requires: 3.0 or higher
Compatible up to: 3.8.3
Last Updated: 2014-3-15
Downloads: 1,563

Ratings

1 star
1 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

0,1,0