Create a taxonomy archive page
WordPress does not offer an archive page for taxonomies from its core. By this I mean a page on which an overview can be found of the terms that fall under this taxonomy. Let’s say we have a taxonomy called “topic” and want to show these topics on an archive page. Posts with for example […]
How to protect your WordPress forms against spam
The reason I started writing this post is because I see a lot of people searching the internet for solutions to protect their WordPress forms from spam. If you are using a plugin like Contact form 7 or Gravity forms you can use for example the Akismet plugin. But if you build your own custom […]
My WordPress base theme
Before the start of every WordPress theme that I develop, I use a simple basis. This is a theme with a number of patterns that I always use. The files and directories css grid.css reset.css responsive.css includes script-enqueue.php helpers.php js main.js images header.php footer.php functions.php index.php style.css CSS directory My css directory consists of 3 […]
WordPress get display name
Depending on whether you have the user’s ID (If not, checkout: Get user ID in every situation) you can get the display name by creating the user object first: When the user object is created you can simply obtain the display name from it as follows:
Get user ID in every situation
WordPress offers a number of options to obtain the user ID. There are various options depending on the situation. There are 3 types of situations: A list of users The current logged-in user A specific user A list of users When iterating over a list of users it is pretty simple to obtain the ID […]
Difference between site url and home url
WordPress has 2 inbuilt functionalities to get the site url: The site_url() will always be the location where you can reach the site by tacking on /wp-adminon the end, while home_url() would not reliably be this location. You can also get this same field by using get_bloginfo( ‘wpurl’ ). The home_url() would be where you have set your homepage by setting General […]
Get featured image url
To get the featured image URL from a WordPress post you first have to be clear which URL you should have. There are multiple sizes of the image available. The default size is “post-thumbnail”, but you can also get the “small”, “medium” and “large” sizes, or custom sizes added by add_image_size(). Use the following function […]
Custom post type archive content
One of the much discussed points of WordPress is the missing archive content of custom post types. Where custom taxonomy terms have their own textarea where you can edit the term content, there is for custom post types no such thing. Fortunately we can create functionality by ourself to solve this problem with the help op the wp_options […]
Extending admin search with post meta
The default search functionality in your WordPress admin is not based on post meta. To be able to search by post meta you need to extend the posts_join and posts_where query functions by adding a filter on both. First I will add the filter for posts_join as follows: Then I add the filter for posts_where: You can add these […]
Extend search with predefined search query strings
Almost every WordPress developer had some annoyance with the basic search functionality of WordPress. Today I customised the search functionality for one of my projects so I am able to add a list of comma separated search query strings to a post where I want it to be found on. So for example a product like “bicycle” needs to […]