Close Menu
Infoceptor
  • Business
  • Finance
  • Technology
  • Health
  • Life
  • More
    • Auto
    • Food
    • Health
    • Home
    • Space
    • Travel

Subscribe to Updates

Get the latest creative news from FooBar about art, design and business.

What's Hot
Flywheel Logo

Flywheel review in 2023

June 8, 2023
Travel restrictions in Canada are different depending on where you're traveling from and to. Here's what you need to know before you go.

Canada: Traveling restrictions and what you need to know before you go

May 19, 2024
If you are planning a trip to Spain, there are some travel restrictions that must be taken into consideration.

Spain: Traveling restrictions and what you need to know before you go

May 19, 2024
Facebook X (Twitter) Instagram
Infoceptor
  • Business
    This guide will show you how to determine the value of your business using different business valuation methods.

    How to value you business – The ultimate guide for 2023

    May 9, 2024
    Have you ever thought of starting your own laundry service? Find out how with this easy guide.

    How to start a laundry service company in 2023

    May 5, 2024
    Learn about the best online payment solutions available to you. Check out what’s available, learn their pros and cons, and choose the one that best fits your needs.

    The 15 best online payment solutions in 2023

    April 27, 2024
    Learn how to create powerful backlinks for your website and increase your site's search engine ranking.

    How to build backlinks to your website

    April 25, 2024
    In this beginner's guide, we will show you the steps involved in creating a mobile app.

    Beginner’s guide on how to develop a mobile app

    April 24, 2024
  • Finance
    Learn how to build wealth and financial security. This article will share steps you can take to build a reliable cash reserve that will grow over time.

    Do you want to build wealth? Here are some ways to grow your money

    May 18, 2024
    Want to know your tax bracket? Check out our article for an overview of the different brackets and what you can expect to pay in 2022.

    Understanding IRS tax brackets – here’s what you’ll pay in 2023

    May 14, 2024
    This article will cover the best electric vehicle battery stocks to buy and invest in.

    The 10 best EV battery stocks to buy in 2023

    May 9, 2024
    The 10 most active penny stocks to watch this year is a list of the most active penny stocks ranked by total volume.

    The 10 most active penny stocks to watch in 2023

    May 8, 2024
    These electric car stocks are making a lot of money and you should consider adding them to your portfolio.

    The best electric car stocks to buy in 2023

    May 8, 2024
  • Technology
    Flywheel Logo

    Flywheel review in 2023

    June 8, 2023
    This article provides a list of the top iPhone models available today. Each model is reviewed based on features, specifications, performance, design and price point.

    Top iPhone models we’ve tested and you should get

    May 17, 2024
    Find out everything you need to know about the Apple Airpods Pro, including their price, features and if they're worth buying.

    Are Apple AirPods Pro a great choice in 2023?

    May 17, 2024
    To help you find the best responsive WordPress themes, we analyzed more than 100 themes and found those that are currently trending.

    The best responsive WordPress themes in 2023

    May 16, 2024
    These sympathy gifts make a great way to show you care while they also help your loved ones get through the tough times.

    The 15 best sympathy gifts that will show you care

    May 15, 2024
  • Health
  • Life
    These sympathy gifts make a great way to show you care while they also help your loved ones get through the tough times.

    The 15 best sympathy gifts that will show you care

    May 15, 2024
    Water bottles are a great way to stay hydrated. This article is dedicated to the most popular water bottles of the year!

    The best water bottles of 2023

    May 10, 2024
    Learn 30 weird and fun facts that will make you question everything.

    30 weird and fun facts that will make you question everything

    May 10, 2024
    Find out which cities in the US are the best for quality of life by checking out this article.

    20 best cities for quality of life in the USA

    May 7, 2024
    There are many ways to print your designs on t-shirts. Check out our list of the best printing services that offer top-notch quality at affordable prices.

    The 10 best T-shirt printing services of 2023

    May 6, 2024
  • More
    • Auto
    • Food
    • Health
    • Home
    • Space
    • Travel
Facebook X (Twitter) Instagram
Trending
  • Flywheel review in 2023
  • Canada: Traveling restrictions and what you need to know before you go
  • Spain: Traveling restrictions and what you need to know before you go
  • Do you want to build wealth? Here are some ways to grow your money
  • Our in-depth review of the Always Pan
  • Top iPhone models we’ve tested and you should get
  • Are Apple AirPods Pro a great choice in 2023?
  • The best shower heads of 2023
Infoceptor
Home»Technology»WordPress»How to use shortcodes in WordPress
WordPress

How to use shortcodes in WordPress

Asih TirtaBy Asih TirtaOctober 5, 20234 Mins Read
Facebook Twitter LinkedIn Reddit Telegram WhatsApp Pinterest Email
Share
Facebook Twitter LinkedIn

If you want to quickly add dynamic content to your posts, pages, or sidebars on your WordPress website – you should use shortcodes.

Many plugins offer shortcodes as a way to add specialized content to your website in the form of image galleries, contact forms, website builders and image sliders to name a few examples.

What is a shortcode?

So, what is a shortcode? It’s basically a code shortcut that lets you pull dynamic content to parts of your website.

You don’t have to have any development skills to add dynamic content to your WordPress pages, posts or sidebars.

Shortcodes are always displayed in square brackets, here’s an example:

[customshortcode]

For security reasons, WordPress doesn’t allow PHP code to be inserted in its database. However, WordPress websites needed a way to run custom code inside posts/pages to show banner ads, contact forms, related posts, and so on, which is the reason Shortcode API was added to WordPress.

Shortcode API allows developers to insert their code to the function, and then register that function to use as a shortcode.

When WordPress sees the shortcode – it executes the code inside it. That way, you, as a user, can use it without any coding skills.

Adding shortcodes (Classic Editor)

Even though it will be discontinued at some point, many people still use the legacy Classic Editor in WordPress. To add a shortcode in the classic editor, create a new post or edit an existing one, and paste the shortcode anywhere in the content box where you want it to show up.

Make sure that it’s in its own line and within the square brackets:

Feel free to use the preview function to see if the shortcode shows up properly in your post or a page.

Adding shortcodes (Gutenberg Editor)

To add a shortcode in the new WordPress Gutenberg Editor, edit your existing post/page or create a new one, and click on the + sign to add a new block.

Use the search function, to search for the shortcode block:

Click on the shortcode block to add it to your post, and insert the custom shortcode (with the square brackets) into the text field:

The plugin usually provides the shortcode, and most of the plugins show available shortcodes during the initial setup. If you’re unsure if the plugin offers shortcodes, check out the plugin’s documentation.

Adding shortcodes to WordPress sidebar widgets

WordPress also allows you to add shortcodes in the sidebar widgets. Head to Appearance -> Widgets option, and drag the Text widget to the sidebar on the right:

Put in any title you want your widget to have, and insert the shortcode in the body area:

Make sure to click the Save button once finished to save changes.

That’s it!

Adding shortcodes to your theme

Even though shortcodes are meant to be used in posts, pages, and widget sidebars, you can also add them to your theme files. If needed, you can edit your theme template, and add the following code where necessary:

<?php echo do_shortcode("[customshortcode]"); ?>

WordPress will automatically display the shortcode output once it detects in the theme.

Creating your custom shortcode

To create your custom shortcode, you need to have some coding skills and developer knowledge. If you’re able to write PHP code, here’s an example that you can use as a base:

// Function that runs when WordPress executes the shortcode
function Infoceptor_plugin_demo() {
// What shortcode does (in this case create a H1 text in red color)
    $Content = "<style>\r\n";
    $Content .= "h1.demoClass {\r\n";
    $Content .= "color: #fc3700;\r\n";
    $Content .= "}\r\n";
    $Content .= "</style>\r\n";
    $Content .= '<h1 class="demoClass">Check it out!</h1>';
// Return the output     
    return $Content;
}
// Register the shortcode itself
add_shortcode('textred', 'Infoceptor_plugin_demo');

So here, we create a function that runs a code and then returns the output. To add this shortcode to your posts, you’d simply need to insert it like this:

[textred]

This is a basic example, but it should be enough to get you started.

Final thoughts

Shortcodes are fantastic for displaying dynamic content on your website, but with the addition of the Gutenberg Editor to WordPress, they are starting to get phased out. Gutenberg blocks perform the same function but in a more beginner-friendly way, and developers recognized that so they started switching from shortcodes to Gutenberg blocks.

If you haven’t switched to the Gutenberg editor yet, feel free to use shortcodes. If you’re already using the Gutenberg editor, we recommend switching to Gutenberg blocks as they have a more intuitive user interface.

People also viewed:

How to change your WordPress theme Choosing color scheme for your websiteHow to choose the perfect color scheme for your WordPress website How to configure and use a WordPress website How to increase traffic and enhance SEO on WordPress Localize your website with the best multilingual plugins for WordPress
Design shortcode shortcodes WordPress
Share. Facebook Twitter LinkedIn Reddit Telegram WhatsApp Pinterest Email
Previous ArticleHow to set up your website on Google Analytics and connect Google Analytics to your WordPress dashboard
Next Article How to embed videos in your WordPress website
Asih Tirta

Asih is a Infoceptor Technology writer, she is passionate about how technology can serve people and improve lives. She helps run code camps for K to 12 to teach young girls how to code and open doors to careers in tech for women.

Related Stories

How to configure and use a WordPress website

February 16, 2024

How to increase traffic and enhance SEO on WordPress

December 30, 2023

How to change your WordPress theme

December 29, 2023
Choosing color scheme for your website

How to choose the perfect color scheme for your WordPress website

September 7, 2023

Comments are closed.

Connect
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
  • LinkedIn
  • Reddit
  • TikTok
Don't Miss
Flywheel Logo Reviews

Flywheel review in 2023

By Matthew Drummond

Flywheel is a fast-growing web host that offers high-performance WordPress hosting for agencies, designers, and developers.

Travel restrictions in Canada are different depending on where you're traveling from and to. Here's what you need to know before you go.

Canada: Traveling restrictions and what you need to know before you go

May 19, 2024
If you are planning a trip to Spain, there are some travel restrictions that must be taken into consideration.

Spain: Traveling restrictions and what you need to know before you go

May 19, 2024
Learn how to build wealth and financial security. This article will share steps you can take to build a reliable cash reserve that will grow over time.

Do you want to build wealth? Here are some ways to grow your money

May 18, 2024
  • Auto
    • Auto Reviews
    • Electric
    • Insurance
  • Business
    • Company
    • Government
  • Entertainment
    • Movies
    • Music
  • Finance
    • Credit Cards
    • Crypto
    • Market
    • Personal Finance
  • Food
    • Coffee
    • Drinks
    • Holidays
  • Health
  • Beauty
  • Fitness
  • Food
  • Medical
  • Home
  • Backyard
  • Bathroom
  • Bedroom
  • Cleaning
  • Furniture
  • Home Office
  • Kitchen
  • Life
  • Astrology
  • Family
  • Fashion
  • Outdoors
  • Personal
  • Pets
  • Apple
  • Audio
  • Domain Names
  • Gaming
  • Google
  • Power
  • Reviews
  • Samsung
  • Destinations
  • Gear
  • Services
  • Space
  • Tourism
  • Technology
  • Tutorials
  • Web Hosting
  • WiFi
  • WordPress
  • Travel
  • Shopping
  • Sports
  • Work
  • Stocks
  • Television
  • Web Hosting
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn Reddit TikTok
© 2025 Infoceptor

Type above and press Enter to search. Press Esc to cancel.