Tagtips

Push-to-Deploy with Sail and GitHub Actions

Sail supports deploying WordPress out of the box, without the need of Git or any other source code management tools. This is great for solo-projects, or simple applications with very small teams. With larger teams and more complex WordPress applications, you’ll want a more robust workflow, including pull requests, code reviews, etc. GitHub Actions is one of the best CI/CD tools on the...

What the Queries

I’ve never been a fan of IDEs, complex debugging tools with breakpoints, variable watch lists and all that fancy stuff. var_dump() and print_r() have always been my best friends. Recently I was playing around with the caching arguments in WP_Query, trying to combine that with update_meta_cache() while sticking wp_suspend_cache_addition() somewhere there in the middle, and it quickly became...

An Alternative to @import in WordPress Child Themes

Using Child Themes in WordPress is a great way to modify an existing theme, however the CSS @import directive is slower than it has to be, so you should try and avoid it. Here’s why. If it takes 200ms to load the child theme’s stylesheet, and 200ms to load the parent theme’s CSS, a modern web browser should take approximately 200ms to load both of them, because modern browsers...

Social Menus in WordPress Themes

I’ve seen tens, maybe hundreds of different plugins, all with different approaches at creating social profile links in WordPress themes via widgets, menus, shortcodes, and “insert this piece of PHP code in footer.php” and whatnot.
A few days ago I stumbled on what I think is the right way.

Don’t do_shortcode

Shortcodes are pretty cool, and the do_shortcode function is pretty neat as it can parse and execute shortcode callbacks from arbitrary strings, but that function invokes a fairly large regex every time it is called. That regex looks for all registered shortcodes within a string. For each match, it runs a replacement with a callback function, which also take the time to parse the shortcode...

Don’t Hide the Fact That You’re Using WordPress

There are quite a few blog posts, plugins and hacks suggesting to hide the WordPress version number, or hide the overall fact that you’re using WordPress. Don’t do it — it’s pretty useless. There are hundreds if not thousands of ways to not only find out the fact that you’re using WordPress, but also find out the exact version number, regardless of any plugins or...

Using get_template_part within Shortcodes

The get_template_part function is one of the most useful things available to WordPress theme developers. Although mostly used in themes for public, get_template_part is often used in custom WordPress websites as an alternative to the PHP include or require. When using get_template_part with the Shortcode API, there are two things you should always keep in mind: get_template_part executes .php...

On $matches in preg_match functions

I’ve seen many people define an empty $matches variable before using it in preg_match and preg_match_all functions in PHP. I’ve done it myself, and I was quite surprised to learn that you don’t really have to — even if there’s no match, you will not get an undefined variable notice.

Tip: wp_cron() runs during init

Pro tip: wp_cron() runs during the init action at the default priority, i.e. 10. If you’d like things to be available during your cron tasks, make sure you initialize them earlier: the init action at priority 9 and less, or other actions that run before init — beware of these, since other things might not be available at that time. Also,┬áCore Control is a good plugin to test and debug...