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

top-website-hosting-for-website-performance
How to Find the Right Fit for Your Business Size – WP Engine Alternatives for Small Businesses and Startups with Help from WPRiders
Explore WP Engine alternatives like Kinsta, Cloudways by DigitalOcean, and Pressable. Learn how to choose the right WordPress hosting based on your company size and goals with expert tips from WPRiders—perfect for small businesses and startups!
WordPress Maintenance, Support, Consultancy, Development or Management? [How to choose the one you need]
WordPress started as a blogging platform and seamlessly transitioned to an excellent CMS. According to W3Techs, it powers 43% of all online websites globally. Nowadays, most of the business owners with an online presence on WordPress look for a care service for their website. But an online search will reveal one of the following services: Maintenance, […]
Gravity Forms Entries Inventory Management
Ever needed to limit the number of entries in a Gravity Form? Like, for booking a given number of places in one shot/submission or buying 3 tickets for an event, etc. Here’s an example: I have a 10 places event Someone comes to the website and buys 3 tickets (in 1 submission) Another one buys […]