WordPress Shortcodes: Case Studies

WordPress shortcodes are a powerful but still little-known feature of the content management system. To show ads on your blog, just type in the word adsense. With the post_count command, you can instantly find out the number of posts. There are many similar examples. Feature sets can greatly simplify the work of a blogger.

wordpress shortcodes

Simple Shortcode Example

A novice user needs to learn how to create and use special commands, as well as be able to use ready-made options. To do this, you need to understand what WordPress shortcodes are made of. As an example, take the line [my_shortcode id = 1 color = white] Some suggestion [/ my_shortcode]. In this entry, the user invokes the option bound to the shortcode. The line consists of two parameters.

The first part of the record is an array of id and color attributes. Instead of these values, you can specify any parameters with the desired names in the opening tag. The second part of the entry is text. In order to process it, you must translate the entire record in PHP. The user will receive a line with the following content: my_shortcode (array ('id' => '1', 'color' = 'white'), 'Some suggestion').

If desired, you can use the record without the closing tag indicated above. The line will look like this: [my_shortcode id = 1 color = white]. In this case, only the attributes listed in the opening tag are passed to the function. The specified recording option is used when invoking an option that does not need to receive other information for processing. In order to add a gallery, just specify the ID in the attributes.

How to embed shortcode in WordPress

Using feature sets is very simple. A blogger needs to create a new post or open an existing post for editing. Then you need to switch the text editor to HTML mode and specify the code in square brackets: [showcase]. You can also use attributes. The entry will look like this: [showcase id = "1"].

You can embed any content into shortcodes: [url href = "link to the site"] text [/ url]. WordPress 2.5 introduces a feature set called the Shortcode API. After saving the post, the content of the record is processed. In parallel, the Shortcode API converts shortcodes to execute the functions assigned to them.

how to insert shortcode in wordpress

Appointment

Using this tool, you can create original WordPress themes in the editor without HTML or special knowledge. If necessary, buttons and sliders in the style of an accordion are added. The user can divide the text into columns, connect the gallery, highlight words in any color, insert beautiful lists and pricing tables. Shortcodes allow you to make a blog more functional, and material - expressive and effective. This method of adding interactive elements is used to solve many problems and is very useful in work.

Creating Shortcodes

If the user knows how to print a simple PHP function, then he will easily achieve his goal. To create a shortcode, you need to find and open one of the WordPress functions.php files. Then you need to insert the line function hello () {return 'Hello world!';}. This action will create a function responsible for the output of the specified text. To transform it into a shortcode, you need to insert the add_shortcode () command after the hello () option.

The line will look like this: add_shortcode ('hw', 'hello') ;. After creating a shortcode, the user can use it in notes and on pages. To do this, switch to HTML mode and enter the string [hw]. This shortcode is a good example of how easy it is to create such feature sets.

Using plugins

To facilitate the work, a blogger can download the extension. Using add-ons is the easiest way to get ready-made feature sets without unnecessary settings.

wordpress shortcodes plugin

WP Shortcode by MyThemeShop

More recently, this free extension was distributed as a premium solution. The WordPress shortcode plugin now contains 24 basic elements: buttons, maps, dividers, pricing tables, and more. To get started, the blogger needs to install the add-on and open a text editor. To add a shortcode, click on the β€œ+” icon. The number of settings in the pop-up window that appears depends on the user's choice.

For the button, you can specify a link and text. After adding a shortcode, an editor will appear in the editor containing the element type and parameters. You may notice that using the plugin is quite simple.

Shortcodes ultimate

This is one of the most popular extensions. The add-on is found in every collection of plugins for customizing WordPress. The extension is available to every user. If necessary, paid plug-in add-ons are downloaded. A blogger can work with 50 page layout elements, a shortcode generator, and a CSS style editor.

The plugin has support for several languages. The advantages of the software product include integration with any templates, modern design, original design of buttons, the presence of a custom widget and sliders for the gallery.

Fruitful Shortcodes

This extension is visually simple enough. Software product updates are infrequent. However, the add-on contains all the standard WordPress shortcodes.

A blogger can work with horizontal and vertical tabs, columns, dividers, etc. Added items are instantly displayed in a graphical editor. The user can turn them off for posts or web pages using the "Settings" section.

wordpress setup

Shortcoder

This plugin is also often found in different collections. The extension is updated very rarely. The user can create feature sets using HTML and JavaScript codes. One of the simplest examples is placing an ad unit in text. To do this, create the adsenseAd feature set.

Then you need to add the ad unit code there . Next, you should call it in the post with the command [sc: adsenseAd]. The user can transfer new parameters to the shortcode using the content editor.

Shortcoder plugin is a very flexible tool. You won’t be able to find basic shortcodes here. The user can create the necessary elements by himself.

Easy Bootstrap Shortcode

The plugin allows you to add new design styles for the site. The developers claim that this is the easiest and most affordable extension in WordPress. The text editor panel contains buttons with which you can copy and paste the shortcode. The plugin has font support with icons. The user can add styles and other elements of the site.

The extension was created to work with the grid of the web resource, so it has many settings for the columns. A blogger can create several blocks, as well as indicate sizes and indents. The plugin supports adaptive layout. The user can also work with basic shortcodes: tabs, lists, buttons, tags, sliders, etc.

wordpress php shortcodes

WP Canvas - Shortcodes

The supplement contains a selection of the most popular feature sets to expand the functionality of the site. The blogger can access not only ordinary elements, but also frames, images with inscriptions, blocks for adding reviews, countdown widgets, process indicators with effects, etc.

The plugin supports custom styles, HTML code, icon fonts. If desired, the blogger can enable the display of a selection of site posts on the page. The developers provided users with only a brief description of the software product. At the same time, the plugin copes with all the functions assigned to it.

Arconix shortcodes

The extension contains 6 types of WordPress shortcodes. The user can work with blocks, tabs, buttons, sliders, etc. The plugin supports fonts with icons. If desired, the blogger can change the login form, turn on the backlight, break the page into columns.

Simple shortcodes

This is one of the easiest extensions for WordPress. After installing the software product in the top panel of the text editor, you can see the button for selecting various elements. It has all the standard shortcodes: tabs, drop-down lists, icons, notifications, etc.

After the blogger learns to create and use feature sets, he can focus on ready-made solutions for the site.

wordpress not working shortcode

WordPress Shortcodes: Customization

How to display a link for posting on Twitter? To do this, open the functions.php file and insert next to other WordPress shortcodes in PHP a line with the following content: function twitt () {return '<div id = "twitit"> <a href = "login page = Currently reading'. get_permalink ($ post-> ID). '"title =" share a note with friends! " > send </a> </div> ';} add_shortcode (' twitter ',' twitt ') ;.

Then you need to switch to HTML mode. Next, enter the word [twitter]. The link will be added where the user left the shortcode.

Subscribe to RSS Feature Set

One of the most effective ways to increase the number of subscribers is to display a correctly formatted message. A blogger does not need to change all of the theme code for WordPress. The user must decide for himself where the feature set will be displayed. The code looks like this: function subscribeRss () {return '<div class = "rss-box"> <a href="link to the site "> Subscription </a> </div>';} add_shortcode ('subscribe', ' subscribeRss') ;.

themes for wordpress

Adding Google AdSense

Many bloggers use the contextual advertising service. Paste the tool code from Google into the theme file is easy. But marketers know that people more often follow links embedded in content. To insert an ad unit anywhere on the page, you need to create a shortcode and call it with the [adsense] command.

Add RSS feed

To complete this task, you need to convert the function to a shortcode. Then you need to enable HTML mode and insert the line [rss feed = "link" num = "3"] in the editor field. The first attribute indicates the URL of the RSS feed, and the second indicates the number of notes to display.

Adding posts from the database

To call the list of articles directly in the editor, you need to create a shortcode, switch to HTML mode and insert the line [liste num = "5" cat = "2"]. This command will bring up a list of five posts from the category with ID 2. It is worth paying attention to the fact that WordPress plugins can display related posts. However, using a shortcode, a blogger can easily get a list of any number of publications from a particular category.

Calling pictures of the last article

To simplify working with images, you can use feature sets. To call the picture of the last post you need to create a shortcode. Then you should enable HTML mode and insert the line [postimage size = "" float = "center"] in the edit field.

Adding feature sets to widgets

It is worth paying attention to the fact that not a single WordPress shortcode is working in the side columns of the site. Platform limitation can be circumvented. To do this, open the theme file for WordPress functions.php and insert the line add_filter ('widget_text', 'do_shortcode') ;. The shortcode will be added to the widget.

Source: https://habr.com/ru/post/K19721/


All Articles