Click here to Skip to main content
15,884,799 members
Articles / Operating Systems / Windows
Technical Blog

WordPress broke my site!

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
8 Oct 2013GPL32 min read 5.2K  
After a quick search, I have found the culprit.

I hear the battle cry of website owners every time WordPress releases an update: “The update broke my site/theme/plugins/heart!” Usually I ignore the wimperings with the knowledge that “good” developers test their stuff with the pre-release versions so there aren’t any surprises.

Well the surprise is on me, now :( The WordPress 3.6 update broke my sites.

The problem:

Here’s the story. I build websites based on WordPress for a small company called Golf Tailor, where we rely heavily on custom themes and plugins that are a mixture of premium and in-house developed code. In my effort to make those sites load a little cleaner, I started using a function I read about online called has_shortcode that I could combine with wp_enqueue_x to only load scripts and styles when needed on a page.

This worked beautifully until 3.6 was released and one of my sites automatically updated. I usually update them myself, but this one is hosted with WPEngine, which will upgrade your site to the latest release unless you specifically ask them not to. Pretty nice feature, until one of my pages quit displaying properly.

After a quick search, I found the culprit was the excellent new function in WP 3.6: has_shortcode. The difference was that the official WordPress version takes two parameters, where the one I was using only took one. That little difference made a huge difference!

The fix:

Since their implementation of it is essentially the same as the one I was using, this is a simple fix: change all the calls to has_shortcode to pass both $content AND $shortcode.

What could I have done differently?

First, I thought I was actually doing good when I wrapped my function definition inside a function_exists. That tells the rest of the scripts that if there’s already a function with that name then use it and ignore mine. This is good practice, but in this case the parameters being different made it not work.

Two additional steps I should have taken (and usually do, this one just caught me off my game) are to prefix custom functions, or encapsulate them in a class.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Web Developer Golf Tailor LLC
United States United States

I build websites.


I like to build things, especially using WordPress.


I'm happy working in PHP, JS, HTML, CSS, and a bunch of other acronyms, but I'm happiest when I find a way to put the pieces together to create something useful.


You can see more of my work at http://coderbits.com/morganestes.




Comments and Discussions

 
-- There are no messages in this forum --