April 7, 2014

One of the reasons why WordPress is so popular these days, comes from the ease with which you can implement and maintain a system. You really don’t need to be proficient in anything but finding the right plug-in for the job. Even embedding audio or video can be a piece of cake, by using shortcodes. Shortcodes come in two types: native and plug-in based. The former are a blessing, the latter may turn into hell.

WordPress by default supports shortcodes for audio, adding captions to images, embedding a link, show a gallery and display a video on a page. Shortcodes are a simple “front-end” — usually ‘code’ that looks like this:

to display an image gallery — to much more complex code that is executed in the back.

The weak spot of shortcodes is that you put them in your content. If you’re creating a post, you would add a shortcode where you want the gallery or video to appear. When you use shortcode, you’re actually mixing content with code. If someone at WordPress would decide a future update to stop supporting a specific shortcode, the consequences are dire: you would end up with a number of posts displaying the raw shortcode instead of the content it’s supposed to replace.

The good news is that WordPress hardly ever changes something that has such a dramatic effect to your content without also making sure there’s an elegant way to fix the problem caused by it. Because, the problem — if it would occur — cannot be fixed easily.

But lo and behold: this is the problem with plug-in generated shortcodes. Plug-ins in the WordPress eco-system are usually developed by people who are doing it out of love for programming, to showcase their programming skills, solve a problem, or sell a service. Nowadays a growing number of them are programming plug-ins in two versions, a light version that you can download for free and a “Pro” version that you need to buy.

The evolution to a paid model is to be encouraged because if it’s successful, it’s a business and the chance of the plug-in developer stopping development of his solution becomes smaller.

Many plug-ins also allow you to use shortcodes and when the plug-in developer has enough of programming for free and especially of delivering support for free, the end-user who keeps updating his WordPress installation will at some point in time end up with raw shortcode inside the created stories — ‘dead’ plug-ins don’t stay compatible forever.

The only way to get those shortcodes out of the story body is to go inside the MySQL database and try to create a GREP pattern that will grab everything related to the shortcode, including the shortcode itself and the content inside the shortcode tags.

Creating SQL queries may destroy your database, but it also is quite hard to find the right table and create the right GREP pattern to find/replace everything related to the shortcode. It may rapidly lead to hell, that place where nothing in your WordPress installation will work anymore unless you restore your system with a database backup — which re-introduces the shortcode problem in the first place.

Thinking through your strategy with regards to shortcodes therefore may save you from having recurring nightmares…

WordPress and shortcodes, sometimes a blessing, often just hell One of the reasons why WordPress is so popular these days, comes from the ease with which you can implement and maintain a system.

12:53pm  |   URL: https://tmblr.co/ZTHVKy1CMeWgL
Filed under: Publishing