Menu
Disclosure: ULTIDA's content is free & reader-supported. We may earn a commission if you click & buy through our links. Your support helps us create the best content & make a difference.
Tutorials

What Is Shortcode In WordPress? (+ How-To)

what is shortcode in wordpress

Have you been using WordPress for a while but trying to figure out what “shortcode” means?

A WordPress shortcode is a small snippet of code usually indicated by square brackets.

I’m sure you have come across the term shortcode even if you’re a WordPress newbie.

Still, many users reached out to us to explain what’s up with shortcodes.

I’ll explain what they are, how they work, and how to create your own.

A shortcode adds a specific feature to your posts and pages.

This post covers:

You can PLACE a shortcode ANYWHERE using the text or visual editor.

It will output the contents on your website’s front-end. (Simple!)

LITTLE effort performs GREAT functions.

how do you use a shortcode in your wordpress website

How Do WordPress Shortcodes Work

Even though WordPress is EXTREMELY flexible, you often need to write code to add extra features.

BUT.

If you’re not a developer, writing code is a MISSION IMPOSSIBLE.

That’s where WordPress shortcodes come in.

They are shortened code snippets that look like this: [audio].

They represent a larger piece of code that WordPress executes from a file where it was added.

By default, six shortcodes come with WordPress:

  • Audio — let’s you embed audio files on your website
  • Caption — adds captions to the specified content. Typically used for images but can be used with other HTML elements
  • Embed — allows you to embed other file types and content in WordPress
  • Gallery — adds a basic image gallery to your site
  • Playlist — displays an audio or video playlist
  • vVideo — allows you to embed video files

The default shortcodes are pretty self-explanatory and perform the function that their name suggests.

Beyond that, many plugins use shortcodes. This includes contact form plugins, image gallery or portfolio plugins, slider plugins, and more.

What is the Use of Shortcode in WordPress

You can use them to add a gallery or a playlist to your post or a page in WordPress. They also work to add content from other websites, such as a Instagram feed.

How Do You Use a Shortcode in Your WordPress Website

You need to copy the shortcode first to add it to any post or page.

Then, log in to your WordPress website and launch the post or page editor.

It’s SIMPLE; paste the shortcode in.

If you’re using the Gutenberg editor, you can use the Shortcode block in the widgets section to add the desired one.

how do wordpress shortcodes work

Keep in mind that some shortcodes ALLOW you to CUSTOMIZE the output.

You can add different parameters to specify exactly what appears as the result of adding a shortcode.

For example, [audio src="audio-file.mp3" loop=”on”] allows you to specify which audio file you want to add to your post or page and set it to loop.

Note: Another thing to remember is that if you’re using shortcodes that came with your theme or a specific plugin, they will STOP WORKING if you change the theme/plugin.

How to Add More Shortcodes to Your WordPress Website

The default shortcodes in WordPress are nice but they’re often not enough.

In some cases, you may want to add a SPECIFIC MESSAGE at the end of your posts or perhaps you want to insert an FAQ section or a button easily.

Luckily, you can add more to WordPress with the help of plugins.

One such plugin is Shortcodes Ultimate.

It has 50+ shortcodes such as accordions, spoilers, drop caps, columns, tabs, and more.

The plugin has 800,000+ active installations and a 5-star rating on the official repository.

We use it, TOO!

how to add more shortcodes to your wordpress website

How to Create Your Own Shortcode In WordPress

Another way is to create your own.

This is useful if you have a specific need or don’t feel like installing an extra plugin with shortcodes you’ll never use.

Here’s how it’s done.

One thing before we proceed: It’s best to create it as a simple plugin that you’ll add to your website if you want to create a custom shortcode.

This will ensure it CONTINUES WORKING even if you update or switch your theme.

For this tutorial, we’ll add the shortcode function to the functions.php file.

First, we need to write the function allowing the shortcode to output our simple affiliate disclaimer.

Paste this into the code editor within your functions.php file:

add_shortcode( ‘disclaimer’, ‘affiliate_disclaimer’ );
function disclaimer_init(){
 function affiliate_disclaimer() {
 return “<p><strong>Links with asterisk are affiliate links which means I may earn a small commission if you use them to make a purchase.</strong></p>”;
 }
}
add_action(‘init’, ‘disclaimer_init’);

Save the file.

Next: Go to any of your pages or posts and click Edit to load the editor.

Locate the shortcode widget and then add yours.

You can then preview the page to make sure it works.

Once you’ve verified that the shortcode is there, you can save the page and continue using it.

To learn more about creating shortcodes, you can refer to the official WordPress codex (I used it at the beginning, too):

Final Thoughts

Shortcodes are useful SNIPPETS OF CODE that make it easy for regular users to add a bit of extra functionality to their website without code.

With the tips laid out in this article, you now know what shortcodes are, what they’re used for, and how to create it in WordPress.

All that’s left to do now is to try your hand at creating a simple shortcode for your WordPress website.

It’s easy!

FAQs About WordPress Shortcodes

What is a shortcode in WordPress?

A shortcode in WordPress is a small piece of code, indicated by square brackets (e.g., [shortcode]), that allows you to add dynamic content to posts, pages, or widgets without writing code.

How do I add a shortcode to a WordPress page or post?

To add a shortcode to a WordPress page or post, paste it into the content area where you’d like it to appear. Make sure you are in the Text Editor if you are using the Classic Editor or insert it as plain text using the Block Editor.

Can I use shortcodes in WordPress widgets?

Yes, you can use shortcodes in widgets. If the Text widget doesn’t automatically process shortcodes, you can enable this functionality by adding “add_filter(“widget_text,” “do_shortcode”);” to your theme’s “functions.php” file.

How can I create my own shortcodes in WordPress?

To create your own shortcode, you can add a function to your theme’s “functions.php” file or a site-specific plugin, using “add_shortcode (“my_shortcode,” “my_shortcode_function”);” where “my_shortcode” is the name of your shortcode and “my_shortcode_function” is the function that executes the code.

Are shortcodes safe to use in WordPress?

Shortcodes are safe to use as they are a core feature of WordPress. However, the safety of a shortcode largely depends on the code behind it. Only use shortcodes from reliable sources or plugins.

Can shortcodes be used in WordPress templates?

Yes, shortcodes can be used in WordPress templates by using the “do_shortcode()” function in the template files. For example: “.”

What happens to my content if I change themes or disable a plugin that includes shortcodes?

If you change themes or disable a plugin that includes shortcodes, the shortcodes will no longer be processed. They will appear as plain text in the format of “[shortcode]” in your posts or pages.

Is it possible to nest shortcodes within other shortcodes?

Yes, WordPress supports nesting shortcodes within other shortcodes. However, not all shortcodes are designed to be nested, and improper nesting can lead to unexpected results.

How can I find which shortcodes are currently available on my WordPress site?

You can check the list of available shortcodes by looking at the documentation of your theme and plugins. Programmatically, you can use the global “$shortcode_tags” array to see registered shortcodes.

Can shortcodes include attributes or parameters?

Yes, shortcodes can include attributes to allow for customization. Attributes are added within the shortcode brackets like so: [shortcode attribute=”value”].

About Author

Brenda is a freelance writer from southern California. Her work has appeared on numerous tech and web development websites. When she’s not creating content, she participates in about a million hobbies and spends time with her family.