LATEST >>

Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » WordPress / WordPress Tips » How To Write, Create And Use Custom Shortcodes In WordPress?

How To Write, Create And Use Custom Shortcodes In WordPress?

How-To-Write-Create-And-Use-Custom-Shortcodes-In-WordPress
To put it plainly, WordPress shortcodes are unique labels (short bits of code) that permit clients to rapidly and effectively pull bits of predefined usefulness into their substance. Excessively conceptual? What about a case? – how about we say’s you’ve got a subject (or plugin) that permits you to embed a pack of cool things into your posts or pages, in the same way as tooltips (those little boxes of additional data that occasionally show up when you float over things), segment designs, exhibitions, catches, pullquotes, blockquotes, social networking catches, and so on, and so on.

Well, likely as not, the way you’d go about embeddings such bits of predefined usefulness is by composing a shortcode – or by utilizing a graphical interface (normally available by clicking on some symbol or other found over the visual manager – expecting, for example, symbol exists) to consequently create a particular shortcode.

To read more about WordPress shortcodes, just visit WordPress Shortcodes Codex Page and WordPress Shortcodes_API Codex Page.

Simple Shortcode:

This is a simple shortcode snippet without parameters. Just add it in your Theme Function (function.php) file.

/* ------------------------------------------------------------------------- *
 * Add A Simple Shortcode
/* ------------------------------------------------------------------------- */
function helloworld() {
return 'Hello World!';
}
add_shortcode('hello', 'helloworld');

Now where you want to use it then you have to add [hello] so it will display Hello World! there.

Recommended For You:
What Is New In WordPress 4.7 And How It Is Helpful For My Site?

Advance Shortcode:

This is an advance shortcode snippet with parameters. Just add it in your Theme Function (function.php) file.

/* ------------------------------------------------------------------------- *
 * Add An Advanced Shortcode
/* ------------------------------------------------------------------------- */
function myname($name) {
extract(shortcode_atts(array(
'name' => 'name'
), $name));
return 'My name is' . $name;
}
add_shortcode('user', 'myname');

Now where you want to use it then you have to add [user name="Filip"] so it will display My name is Filip there.

How To Add Shortcodes In Sidebar Widgets?

You know it that it is very frustrating thing is that you can’t add shortcode in sidebar Widgets. You can’t? yes, unless you read the below trick. To allow shortcodes in sidebar widgets, simply edit the functions.php file from your them and add the following code and then follow the upper way to ad shortcode…

add_filter( 'widget_text', 'shortcode_unautop' );
add_filter( 'widget_text', 'do_shortcode' );

WordPress Shortcode Online Generator:

This tool is given by GenerateWP that have many online WordPress snippet /codes generator tools and one of them is Shortcode generator. Use this tool to create custom code for Shortcodes with add_shortcode() function. This tool has a lot of features like…

  • Fill in the user-friendly form.
  • Click the “Update Code” button.
  • Copy the code to your project.
  • Or save it as a snippet and share with the community.
Recommended For You:
Some Steps That Could Save SEO While Changing Domain Names

So now open GenerateWP Shortcode and generate your code by just filling the form in one click.

Theme Files Editing Warning:

Keep in mind that every code that you will add in your themes files will be removed when you will change the theme. So after changing your theme, you have to follow this article again and you will get everything back same as it is now.

Last Words:

This is what we have and shared in easy steps for newbies so that they can easily know how it works. Stay with us because we are going to share a whole guide step by step about WordPress and make it easy for you. If you liked it then share it and be with us to get next tutorial. If you have any problem then feel free to ask us. We will help you with what we can or have.

You Like It, Please Share This Recipe With Your Friends Using...

2 Responses to “How To Write, Create And Use Custom Shortcodes In WordPress?”

  1. Thank you for sharing your ideas here, I was really struggle with this short-code for my website, a beginner that still learning new stuff on WordPress.

Leave a Reply

Your email address will not be published. Required fields are marked *