If you wish to add any additional code to a WordPress site, where you place it is important. If it’s theme specific code you should add it to `functions.php`, in the theme folder. For CSS you should add this to the theme customizer. If the latter is not available to you, your theme may have a `custom.css` file for this. If it’s not a theme specific change then I create my own, single-file plugin.
A lot of my code snippets over the years have gone on to become full-blown plugins in their own right but there is still some code that remains in my site plugin. So I thought I’d share them.
Remove WordPress Version
This first one removed the version of WordPress that you’re using from your meta data in the header. A useful security caution, as it prevents you from potentially giving away the fact that you’re using an insecure version of WordPress.
Allow Shortcodes in the Feed
As the name suggests this allow shortcodes to be actioned within your RSS feed. Use with caution!
Add Your Own Avatar
Is there a fun image you’d like to use as the default user image if they don’t have a Gravatar? This is what you need – just replace `[your image]` with the location of the image on your `uploads` folder.
Show Post if Search Returns One Result
Few things in life (okay, I exaggerate) are more annoying than searching for something, getting one result and you still have to click it to view it – this rectifies that. Thanks to my fellow Automattician Kailey for the original code.
Highlight Old Posts
There are lots of plugins that will add a message to your posts when they’re greater than a specific age (say, 2 years) but that isn’t what I wanted – after switching themes and generally rebuilding this site a lot of images were broken, etc. I went through the posts, fixing them, until a specific age – I therefore wanted to highlight any post before a fixed date (i.e. where I’d got to). This, simple piece of code, does this. Obviously, change the message and date to taste.
Add a Default Image to Jetpack Related Posts
Due to the aforementioned changes to my site a number of posts no longer have featured images and may not include an image either. This code allows you to specify an image that will appear as a default in such situations. Replace [image url]
with the full URL to the default image.
Do not add any context below each Related Post
More on related posts – this simple filter will remove the context below each (normally it will say why it’s shown, for example it’s in the same category). I remove this because I don’t use categories but it still displays this as the context reason.