Schedule a Free Consultation

Add shortcode parameters via dialog using TinyMCE toobar

Read Article

Have you ever needed to create a dialog for adding shortcodes with parameters in a user friendly way?

We created a TinyMCE interface that inserts a shortcode and its arguments via a modal window, helping authors become productive and prevent any errors.

Content developers using WordPress frequently enhance the TinyMCE editor with plugins that generate pieces of content. When WordPress renders the content of a post or page, any shortcode and its arguments in the source code is replaced with the intended content. Behind any shortcode, there is a plugin whose job is to gather information from parameters and adapt the generated output.

To indicate where an editing plugin will generate its magic, authors have to remember the shortcode that will trigger the content. Unless the code is trivial, the shortcode offers arguments and values. While shortcodes give authors a quick way of inserting complex html code, the drawback is having to remember the name of the shortcode and its parameters. In this article, we present a solution for content components that makes it much easier for authors to include a specific shortcode.

Slider shortcode

One of our customers wanted to include image sliders in a site’s posts and pages. We recognized the benefits of providing a shortcode, so we developed the plugin that generated the slider. For example, authors would have to type the following shortcode:

[wpr-slides wpr_slider=”416” wpr_default=”5”]

The wpr-slides is the shortcode name, while wpr_slider and wpr_default are parameters indicating the identifier of the slider set and number of images to show, respectively. The plugin works wonderfully, rendering code that slides the images in the selected set.

This is great, but how about making it even easier to use?

Adding user interface components

TinyMCE is a powerful editor, providing text formatting icons and buttons. Furthermore, developers can extend the functionality of this editor by using its hooks to add callable functions which either add toolbar buttons or render content. Our plugin provides the following:

  1. An additional button in TinyMCE’s toolbar – place the cursor where the slider shortcode will appear, then click the slider button.
  2. A model dialog with two dropdows – one contains a list of slides already defined, the other a list of default number of images.

After clicking the interface button, the dialog appears. After selecting the slider in the dropdown, choose the number of images to show in the slider. Click OK in the dialog, and a nicely formatted wpr-slides shortcode is inserted. Save the post or page, view it, and call is “job done.”

Here is a short movie of how it works:

Slider shortcode

Benefits

Two prominent benefits of using this approach to inserting shortcodes are worth mentioning:

  1. Reduce your cognitive load – content authors no longer need to memorize the name of the shortcode and its arguments.
  2. Be more productive – no longer would authors need to remember the slider identifier or the maximum number of images allowed, as these options are included in the dialog design.

Additionally, authors can easily move the code manually, allowing freely editable content and design.

Plugin Code

Following we include the complete plugin source code. Before inspecting it, it is worth mentioning the strategy behind it. You will recognize the use of hooks into the TinyMCE’s editor to specify the addition of a standard button, and designing the dialog responsible for selecting the information to include.

To view the code plugin code, visit:

https://github.com/ovidiuirodiu/CPT-smart-slider-scroll/blob/master/wpr-cpt-smart-scroll.php

Navigate to

Check some other articles we wrote

Effective business directory layout saves time
Choosing a business directory layout makes a difference. For a business site that wants to attract visitors to its content, deciding on how to present the data is as important as it is difficult. In this article, we present a novel and interesting method of showing categorical information. When presenting data organized in categories, the […]
Best Hosting Providers When Starting Out With WordPress
When you go on vacation, do you book a hotel, or do you go for an Airbnb rental? I usually like renting either an apartment or a small house, and if you’re like me, then you’ll know how important picking a place with a good host is. Sure, the place you’ll be renting is also […]
5 WordPress mistakes you’re making and how to solve them
Everybody makes mistakes. Maybe some of them might be small, like buying the wrong kind of milk, while others can be more serious, like forgetting to bring your gift to someone’s birthday party. Bottom line is that every single one of us makes mistakes. And to be honest, mistakes are not entirely bad. More often […]