WordPress Shortcodes with and without plugins - Profit Hunter

WordPress Shortcodes with and without plugins - Profit Hunter

Shortcodes are a handy thing that shortens your time on the site. You only need to prescribe the necessary code once, then call it by typing only a few characters in square brackets (for example, [mycode]). In addition, there are some pretty interesting shortcode plugins that help to diversify the design of a WordPress blog. We will tell about them too.

Simple examples of setting shortcodes

In order for you to understand how short codes are set and how short codes work, let's give a couple of simple examples.

Greetings. If you write a greeting in your blog in every post, then it takes some time. It can be shortened in this way:

function easycode () {

return'Good day, dear reader of the blog site. ru! ';

}

add_shortcode (' hello ',' easycode ');

This function is written in Functions. php before brace? at the end of the file. To call it in the right place of the post, we prescribe such a shortcode "[hello]". Instead, the article displays the greeting phrase.

RSS feed offer. You can paste it anywhere just by typing a small shortcode. Here’s what the function looks like:

function rss_feed () {

return 'Be the first to know about new articles!';

}

add_shortcode ( 'fd', 'rss_feed');

The shortcode will be: [fd].

Fast nofollow. How do you insert this attribute into the outgoing link when creating a post? In WordPress for this, you should switch in the editor of posts to the code editing mode, then find the link in the sea of ​​codes and manually add rel = ”nofollow”. Long, right? And here is an easy solution for defining a shortcode that will reduce your work:

function post_nofollow ($ attr, $ content = null) {

$ link = explode ("href”, $ content);

return $ link [0]. 'rel = ”nofollow” href'. $ link [1];

}

add_shortcode ('pn', 'post_nofollow');

After adding these lines to Functions. php, you can write in the article "[pn] outgoing link [/ pn]” - and the link will appear with the necessary attribute. Here is how it is done in the post editor:

WordPress Shortcodes with and without plugins - Profit Hunter

And the link looks like in the source code:

WordPress Shortcodes with and without plugins - Profit Hunter

Other shortcode cases

Creating an information block highlighted in a different color, frame, etc. Within the functions, you can define styles for buttons, text, and other elements. This allows you to beautifully highlight the important information on which to focus.

Adding an initial letter to articles . The appearance of posts becomes more attractive and unusual.

WordPress Shortcodes with and without plugins - Profit Hunter

Content is shown only to registered users. You can hide something very useful and give access only after registration.

Display of the PDF file in frame . This is convenient because you can view the file without downloading or opening in another window.

Display ad units. Sometimes you need to insert ad units Gugd Adsense or Yandex. Directly to certain places, and here shortcodes can be useful: instead of looking for a suitable ad code every time and inserting it in the right place on the page, you can create your own shortcode.

Insert shortcodes into widgets and template files

By default, short codes cannot be placed into widgets in WordPress, but you can break the restriction by outputting one line in the functions file:

add_filter ('widget_text', 'do_shortcode');

If you want the shortcode to be executed, for example, on all static blog pages, you can write in the page file. php in the right place the following:

. ? php echo do_shortcode ('[your_shortcode]');?.

Plugins for displaying shortcodes

If you don’t want to bother with writing functions, then you will find plugins with sets of interesting shortcodes. Just keep in mind that any wordpress extension slows down the site to some extent, so use them wisely. We present an overview of interesting solutions for displaying shortcodes.

  • Easy Boostrap Shortcodes

Very useful for inserting basic elements, such as loading bars, columns, drop-down menu, labels, effects for images.

In addition, it is possible to use various icons with it. The developers of the plugin did a good job on their library, so you will have a large selection. Icons can be used wherever you wish (for example, on buttons, in titles, etc.), change their color and size.

Shortcodes do not need to register yourself: the visual editor has special buttons

WordPress Shortcodes with and without plugins - Profit Hunter

and various visual settings:

WordPress Shortcodes with and without plugins - Profit Hunter

Link to the plugin: https: // wordpress. org / plugins / easy-bootstrap-shortcodes /.

  • Shortcode Ulimate

Shortcodes are presented here in an amount of 51 with the ability to search and sort by type. Pleases and a large number of codes, and a variety of icons that can be changed in size. Conveniently, the plugin provides a preview function.

Shortcode Ulimate offers to take notes, insert quotes, permanent links, columns, spoilers, videos, frames, private content and much more.

Link to the plugin: http: // wordpress. org / plugins / shortcodes-ultimate /

As you can see, shortcodes are a simple solution to complex problems. Use your time correctly, systematizing routine operations and directing it in a creative direction.

Do you like articles? Subscribe to the newsletter!

Search

Related Articles