Tag: PHP







How to Conditionally Enqueue a JavaScript File in WordPress

Enqueuing is the WordPress way to add a stylesheet or JavaScript file on a page. We already published a Quick Guide about including your JavaScript in WordPress. This time, though, we’re adding an extra wrinkle: how do you only enqueue a JavaScript file on certain pages of your WordPress site. That’s the focus of this here Quick Guide.


A Code Snippet to Fix WooCommerce 3.0 Lightboxes

I truly love WooCommerce, but there’s one thing I don’t love about it: breaking changes. Working mostly in WordPress, breaking changes generally feel like something scary and challenging that I expect people in other environments to have to deal with—a bit like, say, cobras. The exception is WooCommerce, which brings the cobras right into my house.



Get a WordPress Image’s Attachment ID from its URL with a PHP Function from Pippin Williamson

pippin's plugins | retrieve image id from url
EDIT: As the comments below have pointed out, WordPress in later versions contains the attachment_url_to_postid() function, which is designed to do the job of the code below. However, on at least one project I’ve worked on (a WordPress multisite), WordPress’s function didn’t work and Pippin’s did. I’d try the WordPress function first and Pippin’s as a fallback.

You know who’s really great? Pippin Williamson.