Blog

WordPress PHP shortcodes

Afbeelding WordPress PHP shortcodes

WordPress shortcodes are a shortcut for executing a piece of code. Shortcodes are a piece of text that represents the piece of code. They are super convenient and useful! Read about the benefits and use of shortcodes in WordPress.

What is a shortcode?

The word shortcode is a combination of short cut and code and it is actually a short piece of text that ensures that a certain element comes out on your WordPress website. Each shortcode performs an action on the WordPress website. An example is a shortcode for a button. When you place this code in a text, that button will always be shown. Such a code is often between block hooks ( […] ) and is therefore very useful to use for elements that come back more often on your website.

What are the advantages of shortcodes?

WordPress shortcodes have many different benefits. Initially, shortcodes are much more user-friendly than HTML code or PHP scripts. Shortcodes ensure that you can easily change certain elements. An adjustment of yours also ensures that it also
automatically changes on all pages where you have used the shortcode.
That is also the second advantage: the use of shortcodes will save you a lot of time. You don’t need complicated scripts, but you can create a shortcode once and then use it easily. In fact, shortcodes automate your workflow.

Plugin for shortcodes

In addition, you can collect all shortcodes within a plugin. In case of an update or change of the WordPress theme, the shortcodes will still work. It is even possible to use the shortcodes for different WordPress websites. Very useful if you own multiple WordPress websites.

How do I get shortcodes in WordPress?

WordPress itself has a number of standard shortcodes. Some examples are (*Delete spaces between [ ]:

  • [ embed ]: this shortcode makes it possible to add different attributes to your embed. For example, setting maximum dimensions.
  • [ caption ]: With this code you insert a subtitle or caption with each HTML element.
  • [ gallery ]: with this code you add a simple gallery to your WordPress website.
  • [ audio ]: This code allows you to insert different audio files.
  • [ video ]: This code allows you to embed and play video files.
  • [ playlist ]: This code allows you to show some audio or video files.

Using WordPress shortcodes is easy, but you need to know how to apply it. In addition to the standard shortcodes, you can also create shortcodes yourself. If you are not handy with PHP and HTML, you can also use a plugin to create your own shortcodes.

Insert shortcodes in WordPress

Shortcodes can also be inserted by means of a widget. This can be done with every page, blog or any other page. It is quite easy to add in the editor. For the people who don’t know how to do it, I have made a small step-by-step plan.

  1. Go to the editor in a post or page.

  2. Click +

  3. Look for the block shortcode / or type it in the search bar

  4. Click the shortcode widget

WordPress shortcodes insert widget

Create your own WordPress shortcode

If you have never created a shortcode before, it is wise to first make a backup of the file that you are going to change. If something goes wrong, you can always go back to the previous version of your WordPress website. To create a shortcode you need to place the piece of code in your ‘functions.php‘ file. You can call up the shortcode with ”[shortcode]” in your messages.

Here’s an example of what a shortcode looks like:

function my_shortcode_function() {
$i = '
WordPress Onderhoudspakketten
';
return $i;
}
add_shortcode('my-shortcode', 'my_shortcode_function');

Plugins for WordPress shortcode

Also by means of a WordPress shortcode plugin you can add new elements to the website. This is useful if you have little technical knowledge. Such a plugin gives you the basic shortcode, then you can adjust the code yourself to your own wishes. There are several WordPress plugins available for this, for example ‘ Easy Bootstrap Shortcode‘, ‘ Visual Composer‘, ‘ Shortcodes Ultimate‘ or ‘ Reusable Text Blocks‘. There are many more, but not all plugins offer equally good quality. So take a good look at the rating of the plugin.

Need help? Get in touch!

Are you unable to make certain shortcodes or will the shortcodes be wrong in the frontend? Contact our WordPress specialists, they know how to handle this. You can reach us on 030 20 72 488 or start a live chat. In addition, see what extra options we offer with our WordPress maintenance packages!

Was this article helpful?

Yes No

We'll assist you promptly and professionally!

Check here all benefits.

© WPmaintenance.com 2011 - 2024 | All rights reserved | WordPress Maintenance is part of Artitex