How to amend built-in WordPress Queries before execution
I wanted to update the order of posts shown on a regular category/tag archive page. At first I thought I’d have to write my own custom query for that, which would have meant a great deal of fudging an existing template that worked fine as it was. All I wanted to do was to amend a single parameter of the existing query WordPress was generating under the hood. Lo and behold, there’s the beautiful hook we can use for this very purpose: pre_get_posts(). This is fired after all parameters for a regular WordPress query are setup, but...
read moreCreating simple Shortcodes in WordPress
I’ve built my very own shortcode in WordPress for the first time. Quite the adventure! It’s a very convenient and powerful way to call a function without resorting to writing code while you’re writing text. I needed to echo some text that would rely on something dynamic I wrote in PHP. In my post, all I wrote was [whatever], which would then be replaced by whatever came out of my function. I didn’t need any parameters to be passed to/from my shortcode, which is fairly easy. Here’s how I did it in principle: <?php // create your shortcode...
read moreHow to re-open a closed Tab in Firefox
Hey I’ve been there more times than I can count: close one or several tabs, only to think, “dang – I needed to keep that one open. What was that URL again?” Looks like I’m not alone, because many browsers support a feature that lets us re-open an accidentally closed tab. I use Firefox, and here’s how you do that: Right-click on your Browser Bar (next to the plus icon to open a new tab), then select Undo Close Tab. It’s genius! Your most recently closed tab will magically re-open, without having to...
read moreHow to style the WordPress Login Page
It’s relatively easy to add your own logo and a custom message to the default WordPress login page. Several plugins let you do that, but I’m a big fan of a little “hard coding”. It makes it easy to have all changes contained in your own files. Here are the four little helper functions I’ve used to make the login section on my own sites a little more palatable. All of these are done with hooks rather than hacking page templates by the way, so this is PHP and CSS only. Adding your own logo This is the most complex...
read moreHow to remove the Title and Description from Archive Pages in GeneratePress
I’ve been having great fun with the Page Hero feature in GeneratePress, and I wanted to use it for archive pages too. By default however, the Archive Title and Description show up in the Page Hero as well as underneath it. This doesn’t happen on single posts, so we’ll have a bit of work to do to make them not show up twice. Rather than hack the actual archive template page, I found two hooks that can accomplish this nicely: generate_archive_title and generate_archive_description. Knowing of their existence means we can...
read moreHow to display the Category Title and Description in the Page Hero with GeneratePress
I’ve not had the best of luck adding the Category Title with the GeneratePress shortcuts in the Page Hero (the ones using the {{curly}} braces). There’s no shortcut for the description either, so I thought I’d write my own and show you how I did it. First I’ve created two regular WordPress shortcuts for the category title and description, then called them from the Elements section in GeneratePress. Here’s the code for the shortcuts: // Archive Title in Page Hero add_shortcode( 'archive_title', function() {...
read moreWhere is the WordPress is_blog() Function
There appears to be a conditional function sorely missing from WordPress Core. We can test if we’re currently on a single post using is_singular(), or if we’re on a page using is_page() or if we’re on the home page with is_home(), and so forth. Sadly we cannot test if the current page is in fact displaying the blog with something like is_blog(). I wanted to test this condition and display a special layout if true, so I had to write my own. Turns out you’ll have to test for quite a few cases to make this foolproof....
read moreHow to embed your latest YouTube Video with responsive CSS
I’ve recently had to update the code that’s responsible for pulling in my latest YouTube upload on the front page. I had previously used a solution that uses the channel name rather than the channel ID. Apparently that API has stopped working and I had to find a workaround. In addition to making it work again, I also wanted my embed to be responsive and look handsome on all screen sizes. The trouble is that regular iFrame embeds use a static size for the video (like 600×360 or 800×480), but being the future-proof...
read moreRemoving the Link Menu Item in WordPress Admin
Remember the Links Manager in WordPress? This was an option for us to add a custom post type or “link” in the admin interface, so that we could easily link to other websites as something popularised as a Blogroll. Nowadays it’s a somewhat outdated term, and for that reason the whole Links Manager component was hidden by default in WordPress 3.5 back in late 2012. The component is still built into WordPress though and won’t show up by default on newer installations. Older installations that have been continually updated...
read moreFixed: EPIC Games show as “unavailable” in the launcher
I’ve had a small issue with the EPIC Games Launcher more and more recently. Some of my games (usually the un-installed ones) show up as being unavailable. Tell me if you’ve seen this before: This has started happening as for the last four weeks I’d say. I’ve started moving some of my games over to a hard driver other than C, and the size of my library has gradually been increasing if it makes a difference. At first glance it looks like there might be a problem with the game, as if it had been removed from sale. EPIC...
read more