Store WordPress environment variables in a separate file

Load your environment variables from a separate dot file to keep them secure and environment specific

Pull the meta title and description for a post type archive from a page

Control the meta title and description for a post type archive from a Page rather than the Yoast SEO settings

Add a quick link to edit the website's Front Page under the admin Pages menu

Create a Front Page link from the WordPress admin area which provides quick access to edit the homepage of your site

Remove 'current_page_parent' class from the Blog navigation when on archive pages

Remove the current_page_parent class from the Blog page link when on post and taxonomy archives

Redirect loop when site sits behind a proxy service such as Cloudfront or Cloudflare

Solve an endless redirect loop, experienced when your WordPress website sits behind a proxy service such as Cloudflare or Cloudfront

Yoast SEO: Remove or customise the enhanced Slack data meta tags

Learn how to remove, add or customise Yoast SEO's Enhanced Slack Data meta tags according to your requirements.

WPML: hide or rewrite language URLs in language switcher and hreflang tags

Amend the list of languages used by WPML's language switcher, icl_get_languages() function and hreflang tags

WPML's ICL_LANGUAGE_CODE constant always returns the default language within AJAX functions

Find out how to get the currently active language from WPML when using AJAX functions

Change posts_per_page on post type archives, search results and other WordPress pages

Modify the posts_per_page parameter according to the current post type or page being viewed

ACF and WPML: Global Options values instead of different values for each language

Using Advanced Custom Fields and WPML, retrieve a global Option value regardless of the current active language.

WooCommerce: Post Title missing from Product page

If certain Product information is missing from your WordPress theme with WooCommerce support, this code snippet will help.

Add a WordPress Nonce to Log Out menu links to prevent 'Do you really want to log out?' message

How to add a Log Out link to your WordPress menus without encountering the 'Do you really want to log out?' message.

Assign a custom template to one or more post types

When you create a custom template in WordPress it will be available only to Pages by default. With this simple snippet, you can assign templates to one or more post types of your choice.

Order WordPress search results by post type

Learn how to order WordPress' search results by post type with a simple code snippet.

Include Advanced Custom Fields Flexible Layout content in the REST API

If you're using Advanced Custom Field's powerful Flexible Layout fields to create modular WordPress templates then you may find you need to include this content in the REST API output.

How to defer scripts in WordPress

Append the defer attribute to JavaScript files on your WordPress site in order to avoid render-blocking scripts and improve performance.

Include ACF flexible content fields in search queries

Modify the WordPress search logic to include ACF Flexible Content fields for more accurate results.

Allow SVG media images to be uploaded to WordPress

Allowing the uploading of SVG files to the WordPress media library through a simple snippet.

WordPress Rest API: filter Posts using a tax_query

Amend the default posts endpoint of the WordPress API to allow a tax_query which will return posts tagged with a given term.

WordPress REST API: 'Access-Control-Allow-Origin' header contains multiple values

If you're experiencing errors when attempting to access WordPress REST API endpoints between domains due to CORS policies, this code snippet will help.

Cloudflare: enable full page caching with WordPress

Cache the HTML of your webpages on Cloudflare's CDN for quicker loading sites that use less data transfer and lighten the load on your web server.

Visual editor not loading on a site loaded through Cloudfront or other proxy services

If your site sits behind a proxy service such as Cloudfront, you may find the Visual editor of TinyMCE is not available.

“Sorry, you are not allowed to access this page” displaying in WP Admin

After a site migration or after certain types of maintenance, you may see this warning when attempting to access wp-admin.

Disable plugins directly from the database

If your WordPress site is showing a 500 server error due to a faulty plugin, you may need to deactivate the plugin without access to the website backend.

Perform a wildcard search in a WordPress meta query

If you need to run a WordPress meta query where the meta key starts, ends or contains a certain string, you can enable wildcard searches on your site.

Flexible layout; copying first section content across to excerpt on save

Generate an excerpt from your ACF Flexible Content fields for situations where you are not using the standard WordPress content field.

Optimising WordPress for SEO by removing default assets

If you're working on a fully bespoke WordPress theme, there are a number of default assets you can likely remove from WordPress to streamline the loading times of your new site.

Rebuild meta data for media items that are missing it

If some of your WordPress media items become corrupted you may need to regenerate the meta data for those items. Fortunately, that's a straightforward process using this code snippet.