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() …

Pretty print fractions as HTML entities using PHP

David Nash code, html, php 1 Comment

I used this code in a WordPress site but it’s pure HTML. I wanted to take a string, for example “3/4” and convert it to a HTML entity ¾. When there’s no HTML entity I still wanted it to look nice, using <sup> and <sub> for the numerator and denominator respectively. I couldn’t find anything on the web that I could copy and paste so I wrote it myself. Here’s what I came up with: //supply a string, eg 1/2, return eg ½ function str_to_fraction( $str ) { $f = explode(‘/’, $str); if( count($f) != 2 ) { return $str; …

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 …

Listify

Listify: How to display default images based on category

David Nash wordpress 4 Comments

You use Listify, the popular directory listing WordPress theme, but want to set default images on a category basis. Here’s how! To customise Listify, it’s best to use a child theme. Listify supplies a skeleton for you to do this. In the child theme’s functions.php, add this: //set default image for all listings function custom_default_listify_cover_image( $image, $args ) { global $post; //get access to the current post //only apply to listings if ( $image || $post->post_type != ‘job_listing’ ) { return $image; } //get the categories for this listing $categories = wp_get_post_terms($post->ID, ‘job_listing_category’); //if it has a category if( !empty($categories) ) …

Create an auto-complete field in WordPress

David Nash wordpress 114 Comments

I’m working on a project that has a large database – about 14,000 business listings. It also has a page for a user to sign up and select which business they work at. 14,000 is way too many options for a SELECT (drop-down) field and I don’t want to put that much load on the MySQL database either. My solution: an auto-complete text field that reads from the WordPress database. I take it one step at a time, and make sure each step works correctly before starting the next step. Here are the steps I took to do it. Front-end JavaScript …

Listify and FacetWP: How to order results by rating

David Nash wordpress 6 Comments

Listify is a WordPress directory listing theme. It allows users to submit listings (of businesses, for example) and also allows users to rate those listings. It uses the WP Job Manager plugin to manage the listings. For some reason, it’s not currently possible to order the search results by user rating. The theme developers have told me that feature is planned for future releases. If you purchase the FacetWP plugin, it becomes possible for the user to order the results, but rating is now included. It took a little digging but here’s the solution, which I think is fairly elegant. Simply copy …

Linux for WordPress Developers – Part 2

David Nash mysql, wordpress Leave a Comment

In Part 1 of Linux for WordPress developers I covered the Apache web server, domain names, .htaccess and .htpasswd files, and extracting the WordPress files. WordPress uses the MySQL database, which can be a little daunting if you’ve never set one up before. I use Ubuntu and I find the easiest way is to use phpMyAdmin, which if you’ve used cpanel as a WordPress developer you’ve probably used this to import the MySQL dump file. You can install it on Ubuntu by following the phpMyAdmin community docs. Creating a database for WordPress Once you’ve installed phpMyAdmin just visit http://localhost/phpmyadmin/index.php and log …