How To Add Shortcodes To WordPress

When designing your website and/or blogposts it is always nice to add some extra functionality or information to it. Unfortunately not all WordPress themes allow to do this easily. Some block builders are limited(because they are free) and some WordPress themes don’ t allow it, also because they are free.

Adding A Line Break Shorcode [br]

The first problem I had was I wanted to add a line break [br] in the text I could add to my frontpage of a OnePress free theme. I found this great article from WpExplorer explaining it. You have to add the following lines to your functions.php

* ------- Line Break Shortcode --------*/
function line_break_shortcode() {
	return '<br />';
}
add_shortcode( 'br', 'line_break_shortcode' );

This worked perfectly. When you know a bit of HTML it is very easy to edit this code to add other shortcodes to your page.

WordPress Shortcode Plugin

Although the above functions.php doe works perfect, I personally wouldn’t recommend adding big parts of HTML code to your functions.php file. It’s a lot of work and there are several great plugins that can streamline this process for you. My favourite plugin for this is Shortcoder. You can HTML/CSS/Javascript and it is all easy managable from a simple but efficient interface.

FEATURES

  • Create custom shortcodes easily and use them in any place where shortcode is supported.
  • Have any HTMLJavascriptCSS as Shortcode content.
  • Insert: Custom parameters in shortcode
  • Insert: WordPress parameters in shortcode
  • Multiple editors: Code, Visual and text modes.
  • Globally disable the shortcode when not needed.
  • Disable shortcode on desktop, mobile devices.
  • A button in post editor to pick the shortcodes to insert.
  • Supports Gutenberg.