shortcodes Archives - Be Theme Blog Where web designers come for inspiration Thu, 19 Oct 2023 06:49:47 +0000 en-US hourly 1 How To Use the WordPress do_shortcode Function Correctly https://muffingroup.com/blog/wordpress-do_shortcode/ Wed, 27 Sep 2023 13:56:02 +0000 https://muffingroup.com/blog/?p=4609 Desc WordPress is loved by both professional and amateur webmasters because of the ease with which new functionality can be added with plugins and widgets. But there’s a catch: not all plugins and widgets are able to insert content anywhere you want on a site, and they are often constrained […]

The post How To Use the WordPress do_shortcode Function Correctly appeared first on Be Theme Blog.

]]>
Desc
WordPress is loved by both professional and amateur webmasters because of the ease with which new functionality can be added with plugins and widgets. But there’s a catch: not all plugins and widgets are able to insert content anywhere you want on a site, and they are often constrained to displaying custom content in pages, posts, or sidebars only.

Fortunately, you can use shortcodes in order to use custom pieces of code outside of a page, post, or sidebar – such as in the header or footer of your site. In most cases, plugins are developed to be used within WordPress’ visual editor, and widgets usually add code to the sidebar. With shortcodes, you can embed content directly into any WordPress template file, which will be displayed exactly where you place it. This article will focus on the do_shortcode function and how to use it to add new functionality anywhere you want.

What does this function do?

no-repeat;center top;;

auto

shortcode1 How To Use the WordPress do_shortcode Function Correctly

Desc

To understand what the WordPress do_shortcode function does, let’s look at what a shortcode is. Shortcodes are small lines of text that can be added to your site which represent larger sections of code that are processed upon page load. When used, they invoke various functions that have various results (e.g. embedding a video or an interactive map). You can either use shortcodes written by you or you can use a plugin that automates the process and adds the shortcodes on its own.

no-repeat;center top;;

auto

shortcode2 How To Use the WordPress do_shortcode Function Correctly

Desc

The main functionality that WordPress do_shortcode adds to your site is embedding content easier into a theme file, whether it’s in the header, footer, or somewhere within the post loop. Basically, you get to insert content on your blog in a dynamic manner. WordPress’ do_shortcode function allows users to use shortcodes to personalize and improve their websites the way they want, by selecting which shortcode to appear where. It is important to mention that some WordPress plugins are used to generate shortcodes for different purposes, but you still need to implement these codes yourself. The only issue with WordPress is that you might not know where to place your shortcodes.

Another caveat is that when using the do_shortcode function, WordPress has to look through all possible shortcodes with RegEx to find the one that is being invoked, making this method somewhat slower than crafting a new, custom PHP function for what you want to achieve. However, as long as you don’t go too wild with your shortcodes, the performance hit shouldn’t be too bad.

How can you use it?

Normally, shortcodes can only be used in the WordPress editor. For instance, if you’d like to place a WordPress do_shortcode in the header section of your theme, you’ll have to do so manually.

Of course, you’ll have to be prepared to tweak some code by copying and pasting a line. The do_shortcode function can invoke any function you need to add to the website, as well as different features on different theme files, without the usual restrictions. The WordPress do_shortcode function looks something like this:

PHP<br />
[/?php echo do_shortcode("[shortcode]"); ?&gt;<br />
.

When should you use it?

Don’t use the do_shortcode function if you only want to alter HTML markups. You should use it when you want to:

  • Use shortcodes to load dynamic content of any type
  • Insert the Google Ads tracking code in different parts of your site
  • Insert a Google Map, contact form, or other widget content somewhere suitable

The 3-step guide to using the do_shortcode function

You can learn how to use the WordPress do_shortcode function very quickly. Follow these simple steps to use any shortcode on your site, using the header location as an example:

1 – choose the shortcode you want

As mentioned before, when you use the WordPress do_shortcode function you can invoke anything you want. You need to research the different shortcodes available to you with your theme, plugins, and widgets,and then choose the one that you’d like to add to your site. For example, the shortcode for a specific Contact Form 7 form might be

[contact-form-7 id="7"]
.

2 – find the header.php file

no-repeat;center top;;

auto

shordcode3 How To Use the WordPress do_shortcode Function Correctly

Desc

Once you’ve found the exact do_shortcode function that you want to call, you need to find the header.php file in WordPress. The easiest way is to use WordPress’ built-in theme file editor (Appearance > Editor).

3 – add the shortcode in this file

no-repeat;center top;;

auto

shortcode4 How To Use the WordPress do_shortcode Function Correctly

Desc

The theme you are using might alter where you find the header.php file or how it looks . Normally, the code in the header.php file contains multiple div sections. These sections are responsible for how your website looks. The do_shortcode function should be added within the div that is linked to the location where you want the function to appear. Here’s an example of using do_shortcode to add the Contact Form 7 on your site:

<!--?php echo do_shortcode("&#91;contact-form-7 id="?" title="My Contact Form"&#93;"); ?-->

no-repeat;center top;;

auto

shortcode5 How To Use the WordPress do_shortcode Function Correctly

shortcode6 How To Use the WordPress do_shortcode Function Correctly

shortcode7 How To Use the WordPress do_shortcode Function Correctly

Desc

Other tips you should know about

no-repeat;center top;;

auto

search-shortcode How To Use the WordPress do_shortcode Function Correctly

Desc

  • Don’t abuse shortcodes by over-using them. Shortcodes are difficult to fix when they get broken, so try to keep their number to a minimum. WordPress’ do_shortcode is very convenient to use, but be careful not to overwhelm your website. Some themes have more than 200+ shortcodes, and that’s not always the ideal situation.
  • Future-proof the shortcodes when you add them. That is, make sure that the shortcodes you add won’t become obsolete or broken in the future. Document which ones have been added so that you can keep track of them and double-check they still work when your theme or plugins are updated.
  • Learn how to search for shortcodes within your website. If you don’t know how to search for do_shortcode functions, it will be ten times more difficult to modify them if they are broken. The easiest way is to navigate to your theme’s folder in /wp-content/themes/your-theme-name/ and start your search from there.

Final thoughts

Once you understand the usefulness of the WordPress do_shortcode function, it will be difficult to stay away from using it.This short tutorial should have answered all of your questions regarding how to use WordPress shortcodes in any section of your site, and how to keep them working despite changes to your theme, plugins, or the core WordPress codebase.

no-repeat;center top;;

auto

The post How To Use the WordPress do_shortcode Function Correctly appeared first on Be Theme Blog.

]]>
5 Extra Useful Shortcodes You Should Know About https://muffingroup.com/blog/5-extra-useful-shortcodes-you-should-know-about/ Mon, 18 Apr 2016 12:39:48 +0000 http://muffingroup.com/blog/?p=2542 A shortcode is a feature that comes in handy when you need to include special functionality on specific pages of your website. A shortcode is simply a short piece of code that is designed to cut down on having to use repetitive strings of HTML to add identical functionality page […]

The post 5 Extra Useful Shortcodes You Should Know About appeared first on Be Theme Blog.

]]>
A shortcode is a feature that comes in handy when you need to include special functionality on specific pages of your website.

A shortcode is simply a short piece of code that is designed to cut down on having to use repetitive strings of HTML to add identical functionality page after page, or website after website. It is a time-saving feature that can stored in a library to be used again and again, as the need arises.

You can create your own shortcodes, and some web designers do; but if your coding skills are somewhere between nil and minimal, there’s a better way. Simply use a WordPress theme like Be Theme that features a library of shortcodes and the means to implement them. The shortcodes are always there when you need them.

 

Why are Shortcodes Useful?

shortcodes1 5 Extra Useful Shortcodes You Should Know About

Their primary purpose is to access useful functionalities that enable you to incorporate specific functions or content onto your website pages.

  • When shortcodes are available, you don’t need to create your own code.
  • Since you don’t need to create code, you don’t have to worry about organizing and storing the code for later use. Be Theme takes care of that.
  • Shortcodes make modifying a layout, or multiple layouts, a quick and easy task.
  • In the case of Be Theme, shortcodes let you take a design element you see in a demo, and insert it anywhere on a web page.
  • Shortcodes make your life as a web designer easier; they are time savers and productivity boosters.

Be Theme has the features and functionality to accomplish almost anything you want done when building a website, but if it had every single feature you might need, it would tend to become a cumbersome tool to work with.

Shortcodes keep that from happening.

The five useful shortcodes to be discussed here cover a lot of territory. Be Theme’s shortcodes library has more than 40 times that many, ranging from typography and infographics, to content blocks, elements, and loops.  Be Theme has you covered.

 

5 Examples of Useful Shortcodes

shortcodes2 5 Extra Useful Shortcodes You Should Know About

The five examples shown have different uses. What is important however is how to use them. Instead writing code, you simply insert the appropriate attributes into the shortcode. The shortcode will do the work; you only have to specify what you want done.

  • The Portfolio Slider shortcode has five attributes that relate to how you want to present your portfolio. Enter the number of portfolio items, the category, the IDs of various categories (if showing more than one), order by date, menu, or title, and ascending or descending order.
  • The Blog Slider shortcode uses the same types of attributes as the portfolio slider. The use is somewhat different, in that the items presented are typically content from recent posts, or categories of posts.
  • Button shortcodes can be used to create various button styles. You can use a button to link to another page, link to a section on the same page, or for downloading.
  • Column shortcodes are used to build pages without using a page builder. They define the 6 column types. You simply select the type and insert your content.
  • The Map shortcode enables you to add a map of any size on any location on your page. Its attributes are latitude, longitude, height (in pixels), and zoom.

 

Be Theme Makes It Easy

The Shortcode Generator and library is but one of Be Theme’s many features. This, the biggest WordPress theme on the market, can boast of 40 powerful core features, including its collection of 190+ professionally created, fully customizable, pre-built websites.

Be is fully responsive and multilingual, RTL, and retina ready. Other features include a one-click demo import, the premium page builder, layout configuration features and options, and a support team that is second to none. Be is always kept up to date, and once you make your purchase you will receive lifetime updates.

Be Theme, like the shortcodes described here, makes life easier for you.

Further reading: How to Add Extra class in WordPress Menu

The post 5 Extra Useful Shortcodes You Should Know About appeared first on Be Theme Blog.

]]>