Debugging in WordPress

Debugging in WordPress

David Nash code, wordpress Leave a Comment

I know, debugging in WordPress is boring! We’re creators – we want to build cool stuff without worrying about stepping on any toes! But debugging in WordPress is important! Last week I came across this tweet from Jonathan Bossenger (@jon_bossenger): My first instinct was to reply that enabling debugging in WordPress makes in impossible to use, until I looked more closely. You see, every time I set up a WordPress site I have to edit wp-config.php, and that line define( ‘WP_DEBUG’, false ); occasionally tempts me to change it to TRUE. I soon regret it, because my next step is …

Autocomplete with AJAX in WordPress

Autocomplete with AJAX in WordPress: 2019

David Nash code, tutorial, wordpress Leave a Comment

This is the second part of Create an autocomplete field in WordPress: 2019, which works well if you don’t have that many options. If you have less than 10 options, use a select element. Less than 100-1000 (depending), you don’t need AJAX. If you have more than 100-1000, you’ll probably need to use autocomplete with AJAX. This means the page will load faster, and we’ll limit the data to entries that more closely match what the user is looking for. We didn’t even need Javascript for the previous part. What we’re doing now is a bit more complex, so we’ll …

Create an autocomplete field in WordPress: 2019 Update

David Nash wordpress 5 Comments

My most popular post is Create an autocomplete field in WordPress, but it’s been over three years since I wrote that. So I want to visit the topic again, and try to be a bit more thorough in my explanation. So I’ve created a fresh install of WordPress 5.1 on my local machine. It has the Sample Page and Hello World! posts, and everything else that you get with a fresh WordPress install. Previously I’d used jQuery, but we no longer need it. Browsers have come a long way, and ES5 pretty much covers everything. This time, let’s use the …

Migrate from WordPress.com to WordPress.org – Problems and Solutions

David Nash wordpress Leave a Comment

I had a client recently who wanted to migrate from WordPress.com (the paid service) to a WordPress.org self-hosted site so that he could have greater control over his theme and plugins. You’d think it’d be fairly easy. I mean, they’re both WordPress, right? This really seems like something that could be done at the click of a button. But it wasn’t as easy as I’d hoped. Here are the problems I came across and how we worked around them. Problem #1: Names As the saying goes, the two hardest problems in computer science are cache invalidation and naming things (or …

Display WooCommerce category description and custom category titles

WooCommerce category description and custom title

David Nash woocommerce, wordpress 18 Comments

The WooCommerce category description is a good way to increase usability and improve SEO on your site. We can also show a custom category title which is a little more descriptive. To do this, it’s good practise to start with something easy, get that working, and then build from there. Show the WooCommerce category description In the child theme, if it doesn’t already exist, create a woocommerce/ directory. Copy the template file from wp-content/plugins/woocommerce/templates/archive-product.php  to wp-content/themes/[your-child-theme]/woocommerce/archive-product.php. Now we can edit that without changing any plugin files directly (which could get replaced on the next update). In WooCommerce 2.0.0+, towards the top of …

Link WP Ultimate Recipe ingredients to WooCommerce products

David Nash woocommerce, wordpress 3 Comments

WP Ultimate Recipe is probably the best WordPress plugin for creating recipes. It has one major drawback – it’s not possible to link to WooCommerce products on your site. This seems like a feature that online food retailers would want. The WP Ultimate Recipe premium plugin adds the ability to add a link to a product ingredient. This is great if the store doesn’t have many products, or you want to link off-site. What I wanted was to let the site admin search their WooCommerce products without having to jump to a different tab to find the link. First, install WooCommerce, WP Ultimate …

Aw Yiss! WooCommerce Breadcrumbs

WooCommerce Breadcrumbs – Control Product Categories

David Nash woocommerce, wordpress 7 Comments

WooCommerce breadcrumbs will show the first category it finds that a product is in, no matter how you got to it. This makes sense, as breadcrumbs should more be about categories than browser history. Unfortunately if that category is alphabetically earlier, it will display that – no matter how many levels of categories it is deep. It makes more sense to me to show the shortest path of categories to the product, which is what this tutorial is about. I’m going to assume you’re using a child theme for this. If you’re not, sorry – you’ll need to go and set …

Display WooCommerce category description and custom category titles

Woocommerce: Show attributes on single product page

David Nash woocommerce, wordpress 28 Comments

I’ve been working on a large Woocommerce site recently. Woocommerce gets updated regularly and unfortunately the documentation doesn’t always cover the new features. Generally when I come across a new problem I ask Google. It’s easier to adapt code than it is to write it from scratch. To be honest, I find the attribute system a little confusing. I came across this Stack Overflow article, which helped. Then I realised there was a much easier way. Step 1 – Create a Woocommerce action Edit functions.php in your child theme. Add the following: //show attributes after summary in product single view add_action(‘woocommerce_single_product_summary’, function() …

Appearance Customize example code

Appearance Customize – WordPress theme Quick Start

David Nash code, wordpress Leave a Comment

There’s a lot of detailed information on how to add settings under the WordPress Appearance Customize menu. It’s far too detailed if you just want to add a couple of settings. In this example I just wanted to add some simple fields. One for the company title, which differs from the site title. And another for their logo which appears in the WordPress header. Modifying Appearance Customize with functions.php add_action(‘customize_register’, ‘yourtheme_customize_register’); function yourtheme_customize_register( $wp_customize ) { //first we create a section $wp_customize->add_section( ‘yourtheme_theme_options’, array( ‘title’ => __( ‘Theme options’, ‘yourtheme’ ), ‘priority’ => 1000, //(probably) make it the last item …

FacetWP: How to automatically get proximity location in Listify

David Nash wordpress 6 Comments

This issue happened for me in Listify, but it should apply to any FacetWP form you don’t want to refresh. We wanted to display the FacetWP form on the home page, and have it automatically geolocate the user. This can be done simply with this jQuery code, with a click event on the .locate-me element. I found code on the Listify site that should do this, but it causes the form to reload repeatedly. I contacted them but they say they didn’t have that issue. The problem with this is that when the location gets set, the form reloads, causing it to …