The Weirdest WordPress Bug I’ve Ever Encountered…

Posted on

The title of this post is admittedly vague but I really don’t know what else to say: this is the weirdest WordPress bug I’ve ever encountered.

I ran into an issue today where page meta wouldn’t save, specifically neither my ACF meta nor my Yoast SEO meta. I’d fill out the field, hit update, and the field would be empty, with no reference to it ever existing in the database.


I went through the standard debug process and deactivated all of my plugins except Yoast and tried again. Same thing. Deactivated Yoast and activated ACF… same thing.

I started considering that it was my theme. The theme is hand-rolled and uses a well-tested internal framework developed at work, so I was confident that the theme wasn’t the issue. Nonetheless, I switched to a default WordPress theme and tried again.

Same result. What the hell?

I created a new dummy page with dummy Yoast info, saved, and was shocked to see that it had saved correctly. To make sure I wasn’t crazy, I did it again, and experienced the same result: success.

From there, I started comparing the meta between the two posts. The only difference was that the original post had a meta key defining a page template. (I need to point out that this is a new template for an existing WordPress site, so the existing database was duped.)

The page template was for the previous theme. It seemed like a longshot, but I deleted the meta, edited the page, and… violà: my changes saved as expected.

The Fix

To fix/workaround the issue, I deleted all meta entries where the meta_key was _wp_page_template. There were about 50 entries.

Again… What the hell?

I started researching this issue and came across a couple WordPress tickets describing the same issue.

I learned that this bug was originally reported at least three years ago, the first patch was written 17 months ago, and a final patch was accepted 7 weeks ago in the same ticket.

The fix is set to land in 4.2, thankfully!

Long story short, if you’re building a new theme for an existing WordPress site and using a version < 4.2, it’s a good idea to delete the old page template meta when you get to the point that you won’t need it again.


Removing “Related YouTube Videos” From WordPress oEmbeds

Posted on

At work the other day, I needed to remove the related section that appears at the end of a YouTube video. (See photo below) YT lets you do this by appending &rel=0 to the video URL, but unfortunately, WordPress strips this with its auto-embedder.

Never Gonna Give You Up Related Videos

I researched WP’s embed hooks and stumbled upon two: embed_oembed_html and oembed_result. These hooks are similar in that they both affect the output of embedded HTML. The difference is that oembed_result only gets called once and embed_oembed_html gets called every time the link is embedded. (WordPress caches the generated HTML.)

I recommend oembed_result but in my case, W3 Total Cache was affecting the output of the embed so I had to use embed_oembed_html.


Hooking into WordPress Business Directory

Posted on

Today I was working on a site that uses the WordPress Business Directory Plugin (WPBDP). I needed to link a phone number field for mobile devices but couldn’t find anything useful in the plugin’s documentation… so I did what I always do and dug through the plugin source.

I found several useful WP hooks, and was able to write a quick function to do what I wanted. The code below goes into a theme’s functions.php file or a simple plugin.

This assumes that the ID of the phone field is 6. The field’s ID can be found by editing the field and looking for the ID in the URL.

Screen Shot 2014-12-08 at 3.43.50 PM