Category: WordPress Snippets

  • Mass updating values in your WordPress database

    Mass updating values in your WordPress database

    Often when we migrate a site from one domain to another we have to update the values in the database to reflect the URL of the site we are now going to be using. Nowadays we typically use WP Migrate DB Pro to do all the heavy lifting but sometimes we do it manually and this is how…

  • Update: WordPress Loop for a Custom Post Type

    Update: WordPress Loop for a Custom Post Type

    As our post on creating a loop for a custom post type was one of our most popular we thought we would add some updates to this and some better examples of how it works. You may find it better to start with this post if you haven’t read it already. Our original post used…

  • Expanding a div beyond its container to be full width of page

    Expanding a div beyond its container to be full width of page

    Sometimes its necessary to break a div out of its container and make it full width of the page which luckily we can do using a bit of CSS trickery! An example of this for us is where a plugin shortcode was inserted within the WYSIWIG editor which was within a container div and we…

  • Protect your email address on a WordPress site

    Protect your email address on a WordPress site

    WordPress comes with some useful built in functions for sanitising and protecting content which are often underused. For example, ever needed to protect an email address on a site footer or contact template so it cannot be picked up by spammers? Enter ‘antispambot’! Antispambot’s default usage is as follows where the email you want to…

  • Displaying the taxonomy name

    Displaying the taxonomy name

    Sometimes you want to display the taxonomy value for post type and this next bit of code will do just that. Just put this where you want the value to appear in your WordPress themes template file and it will bring back the taxonomy category name. This snippet can go in single.php, archive.php etc and must…

  • Changing the order on a Woocommerce Product page

    Changing the order on a Woocommerce Product page

    We have just completed a WordPress site for client using Woocommerce where the design requirement meant that the order of the elements on the typical Woocommerce product page had to rearranged. In this case the price needed to be moved below the product short description. Using the built in hooks and functions of Woocommerce this…

  • WordPress loop for a custom post type

    WordPress loop for a custom post type

    This post has been updated with newer and better information. Please go here to see the updated version We use custom post types on nearly every site we develop, from sliders to products, custom post types make it a lot easier to separate content so your client finds it easier to maintain their WordPress website.…

  • Setting a template header on a WordPress file

    Setting a template header on a WordPress file

    This is a quick snippet to let you know how to add a template header to your WordPress file so it can be selected in the WordPress admin for use. Say for example you want to have a different page template for your contact page then you will have to create a separate template file…

  • Excluding a category from the WordPress Loop

    Excluding a category from the WordPress Loop

    Sometimes you might want to exclude a blog category from your WordPress loop, for instance you might have a category that you are using for something other than for blog posts. The following piece of code goes right before your loop and you just need to find the category number you want to exclude and…

  • Detecting the browser used and adding a body class

    Detecting the browser used and adding a body class

    This is one of the snippets that we nearly always add to our sites as it means we can target specific browsers and operating systems using conditional css code. The code below goes into your themes functions.php file somewhere between the opening and closing php tags and it adds an additional class to your body…