Add a custom field to every public post types in WordPress with Advanced Custom Fields

Add a custom field to every public post type in WordPress by pasting this to your functions.php. Make sure you have Advanced Custom Fields Pro installed and activated. The custom fields will appear as a Option Page in WordPress admin.

 

Print the custom field on the archive page by adding this to the template file.

 

Custom logo in WooCommerce Storefront

Add this to your functions.php in your theme or plugin to add a custom logo in WooCommerce Storefront. Make sure to change the image source to what ever you want.

 

Generate custom XML sitemap on post save in WordPress

It’s not pretty, but it works. The script generates a custom XML sitemap on post save in WordPress. It’s looping through every page for every post with the post type “city” (since it’s unique content based on what city you choose). Remember to also use the URL parameter tool in Google Search Console to make the crawlers index the pages correctly. Since we use Polylang, the script will create a sitemap for each language.

Don’t forget to create the folder “sitemaps” in your theme folder and make it writable.

 

Disable payment gateway for specific user role in WooCommerce

Disable a specific payment gateway in WooCommerce by adding this to your custom plugin or function.php in your theme. You can also add multiple user roles with the plugin Members and change payment gateway for different roles.

 

Force HTTPS in htaccess and wp-config.php

Force HTTPS in WordPress by adding this to your htaccess-file, before the line “# BEGIN WordPress”.

 

Also, add this to your wp-config.php. FORCE_SSL_ADMIN is there to make sure there’s no redirect loop in wp-admin.

 

Remove query strings from static resources in WordPress

Remove query strings from static resources in WordPress by adding this to your functions.php. You can also change the substring “?ver” to anything else you want to remove.

 

Featured image URL from Post ID in WordPress

Get featured image url from post id in WordPress, for when you’re to lazy to google it. This includes a custom image size as well.

 

Execute code on create, edit or delete taxonomy terms in WordPress

 

Upload image from URL and set as featured image in WordPress

 

Sort tags and categories with ACF in WordPress

Start by adding a custom field to your tag or category with Advanced Custom Fields, name it to “custom_field” or something, and add this to your functions.php.

 

Modify the tag or category object in the loop by getting the custom field, but it back, sort it and use it how you want.