Tagtips

Reminder: Don’t Use the Short PHP Open Tag

Jetpack 2.0.1 was released last night, immediately followed by 2.0.2, which fixed a fatal error on some hosts, caused by a short PHP open tag. So here’s a reminder: never use the short form of the PHP opening tag: <? _doing_it_wrong(); ?> Always use the long form: <?php _doing_it_right(); ?> If your grep can do Perl regular expressions, you can search your entire codebase with a...

WordPress E-mails in HTML

WordPress sends e-mails in plain/text by default, and you can change that using the wp_mail_content_type filter. However, if you change the content type to text/html for all your e-mails, you might break some messages that contain links, because WordPress puts <angle brackets> around links. From the RFC2396: Using <> angle brackets around each URI is especially recommended as a...

WordPress Actions vs. Filters

If you’re still wondering about the difference between WordPress actions and WordPress filters, Michael Fields posted a very cool explanation in this forum thread called Actions vs. Filters. I think it’s the best explanation of actions and filters I have seen so far, well done Michael, and keep up the good work! Let’s pretend that WordPress is a Mexican restaurant and we have...

Don’t Be Shy to Use sprintf with WordPress

Don’t be shy to use the printf and sprintf functions with WordPress. It makes code much easier to read. Take a look at the following examples. echo '<a href="' . get_permalink() . '" class="link">' . get_the_title() . '</a>'; It looks quite dirty and it’s very easy to miss a quote or double-quote. Here’s one that looks a lot cleaner and easier to read: printf( '<a...

Github’s Asking for my Password

“Why is Github asking me to input my username and password when I try to push changes to a repository I own?” I asked this myself a couple of times before I figured out I had cloned it the wrong way: git clone . As opposed to: git clone git@github.com:kovshenin/publish.git . Where the former will use the HTTP protocol, and thus require basic authentication (username and password), and...

Quick Tip: How to Make Tweet Embeds Responsive

Twitter embeds were introduced in WordPress 3.4, allowing you to insert tweets by pasting a link to that tweet on a line of its own, in you post or page content. However, many responsive themes (including mine) resulted in broken layouts on narrow screens, since the embedded tweet will get a fixed width of 550 pixels. After a little poking around, I found an easy way to solve this with some CSS...

Tip: get_posts will suppress_filters by default

I was wondering why my posts_where filter was not being executed on my WordPress query and after a bit of poking around, I figured out that get_posts sets suppress_filters to true, unless specified otherwise, making WP_Query skip a bunch of SQL filters, including the posts_where I was trying to set. So learn the easy way — get_posts will suppress filters by default. Hopefully this...

Nonces on the Front End is a Bad Idea

Here’s a tip! Don’t add nonce fields on the front end of your site for logged out users. That may cause trouble with page caching plugins, which will serve HTML from cache with the nonce field, even if the nonce has expired. Also, nonces don’t really help prevent spam in contact forms, etc., especially for anonymous visitors. Nonces are used for security.

Go Beyond Draft-Publish-Pending in WordPress

If Draft, Pending, and Publish don’t suit your needs, you can always add more with register_post_status, which will take care of pretty much everything, except the admin UI where you actually have to pick a post status. Ticket #12706 takes care of that, so feel free to try out the existing patches, and report back to Trac.

Meet the WordPress Honey Badger

I can’t believe I missed this awesome blog called WP Honey Badger. It has some sweet tips on how not to do stuff in WordPress, along with links to relevant articles and Codex entries. The blog is quite slow to load, but that’s probably because the WP Honey Badger “don’t give a shit” about good hosting.