Jun 29, 2012

What are and how to create shortcodes

Filled under:

What are and how to create shortcodes
If I read a while you probably know a lot of " shortcodes "for use in WordPress. Its greatest virtue is that you save time on repetitive tasks regularly , and for that alone is worth using them, and even learn how to create them.

There are many current issues are " shortcodes "included, as all of Elegant Themes or WooThemes , but if your item does not include them nothing happens, you can use all we have learned shortcodes in WordPress Support or, as we shall see now itself, create your own, it is very easy.

1. What are the WordPress shortcodes for?

The WordPress shortcodes are small pieces of code you can add in the WordPress editor. are used to add functionality to the content of your posts and pages without writing a script each time you need to do the job.

HTML tags are like using brackets ( [] ) instead of the symbols of "greater and less than" ( <> ). Come on, something like this:


You can add "shortcodes" manually by a code in your file ( functions.php ) function or plugin from the subject if it includes or from some plugins that offer "shortcodes" ready to use (a good example are the plugins embed videos that use shortcodes type [video = url_del_video] . "

2. Advantages of using shortcodes

The main thing is not having to repeat code or routine tasks in the WordPress editor. The shortcodes are great time savers. They also facilitate tasks that require tedious or usually much typing. You can use them to add repetitive texts, to make function calls to implement CSS classes, almost everything.

3. Disadvantages of using shortcodes

The shortcodes that you believe have virtually no disadvantages, but not those that make it easy themes and plugins. The reason?, Very simple, creating a dependency, as if tomorrow you change your theme or plugin and you used your shortcodes have much cleaning to do these shortcodes to stop working.

4. Creating WordPress shortcodes

The first is to choose the PHP file "host" the functions of the shortcodes. The most common choice is the file functions.php the current theme, which include almost all, and I think it manually. You can also create your own plugin functions , an option usually cleaner and more controllable.

The two basic steps are these:

  1. Create the primary function PHP 
  2. Create the connector add_shortcode , whose function is to connect the primary function to WordPress PHP (create the shortcode for the PHP function and then insert it into the WordPress editor to activate this feature)
As I have stated, once you insert the [shortcode] into your editor, WordPress will connect to the file functions.php or plugin functions and automatically replace the shortcode with the function you created.

Once you've created functions, whether few or many, all you have to do is insert the shortcode associated with each function unique every time you want to use in your editor.

1 - Open the file functions (functions.php) of your subject, usually in / wp-content/themes/tutema/functions.php , or the plugin function and create the function

A simple example would be something like:

function shortcode_gracias() {
return '<p>Thanks for reading my blog!, if you liked subscribe to the RSS feed</p>';
add_shortcode('thank you', 'shortcode_gracias');

Save the changes file functions, you're ready to use your new shortcode. 

2 - Put the new shortcode [thanks] in the place you want your WordPress editor 

Once you save changes to your page will look like the result of the "call" to the shortcode, looking something like this: 

Thanks for reading my blog!, If you liked subscribe to RSS feed 

That's it!, Just created your first shortcode yourself . Now you only need to experiment, learn, and test to customize your WordPress while you lose the fear of "touching code." 

To grow and learn more here I leave the required references should not miss : 


Post a Comment