Tuesday, September 24, 2013

Creating custom shortcodes codes in Wordpress

If you need some custom shortcodes, you have to add a few lines in your theme's function.php file.

First, create the function that you want to use. In this example we'll just make the text red between [red][/red].

 function makeRed($atts, $string) {  
      return '<span style="color: #ff0000;">'.$string.'</span>';  

Next we need to register our function.

 function register_shortcodes() {  
      add_shortcode('red', 'makeRed');  

Finally, we need to make the whole thing work.

 add_action('init', 'register_shortcodes');