Posts relating to
WordPress development
Nesting CSS Media Queries
October 28th, 2018Processing styling rules based on certain criteria, such as viewport width, is achieved using the @media conditional group rules. As of October 2018, all modern browsers support nested @media queries. What’s a @media query? Here’s a simple example of a media query to make the text 10% bigger on devices with a screen (viewport) wider than 768px […]
Adding Feature Images to the WordPress RSS Feed
October 26th, 2018The WordPress RSS feed is great. We use it with third-party services, such as MailChimp. One key datum that isn’t included in the feeds by default is the featured image for posts (and pages). This article will address that with a simple ‘action‘ hook that adds the featured image to the item’s feed. /** * […]
How to trim words by character limit
October 21st, 2018We recently encountered a scenario where the client wanted to trim the news items titles to a maximum number of characters, whilst respecting words. Our research revealed that this seemingly obvious requirement wasn’t elegantly solved. As most of you will know, there are solutions for trimming by characters or trimming by words, but neither of […]
WP Code Tip: get array of post IDs
October 18th, 2018A number of times over my years developing in WordPress I’ve needed to extract the post IDs of the posts in an array. And every time I need to do this I use the wp_list_pluck() function, from WP_List_Util, the WordPress list utility class. And every time I use this really handy helper I mean to […]
How to fix ansible/vagrant ERROR! the role ‘swapfile’ was not found
August 21st, 2018This article provides a simple fix for the ansible error, “sorry, tersmitten.swapfile was not found”, by updating 1 (maybe 2?) .yml config file. If you have encountered the above error, or “ERROR! the role ‘swapfile’ was not found”, then chances are you are using a dependency that is no longer supported (or more precisely, it […]
How to prevent Yoast from setting noindex on pages
August 13th, 2018On a few occasions Yoast has inexplicably injected a noindex meta tag in the head of pages that I want search engines to index. I’ll get to the bottom of this when I have a free block of time. But, but for now, a really simple way to keep the meta tag away, is to […]
How to call wp_get_attachment_image() without srcset
August 10th, 2018Sometimes it’s nice to have all the goodies wrapped up in a nice little function, such as wp_get_attachment_image(). This is a great function that generates the entire html for an image tag, including srcset and sizes. However, wouldn’t it be great if sometimes we could get all the goodness from this wonderful function, but just […]
A simple filter to hide specific widgets on specific pages
August 10th, 2018It’s not uncommon to only want to show specific sidebar widgets or footer widgets in certain views. In the case below we didn’t want to show a client’s teaser widget of their recent installations when the visitor was already viewing any of their portfolio pages. So here’s a simple filter that does just that: /** […]
How to disable directory views with a blank file or a single line of code
August 8th, 2018By default the directories (folders) of your website and other applications may be publicly viewable for all to browse. This is a potential security risk, but thankfully one that can be reduced very easily. Here are two simple options to reduce this risk by preventing the directories from showing their content as browsable lists: Option […]
Demote Yoast’s meta box priority to ‘low’
August 7th, 2018The Yoast meta box sits just below the main editor. To demote it, aka, reduce its priority, just add this anonymous function to your theme (or better still, a custom plugin): add_filter( 'wpseo_metabox_prio', '__return_false' ); Or, you can use the more commonly quoted approach of explicitly stating the meta box’s positional priority to ‘low’: add_filter( […]