
WordPress code snippets for hooks, custom post types, the REST API, WP_Query, admin screens and more. Copy, paste and adapt.

Put an Add Media upload link on the WordPress admin bar, in wp-admin and on the front end, for users who can upload files.

This is a snippet for Oxy Ultimate Woo plugin that allows you to change the default “No product in cart” to anything you like. Credit to the Developer, you can see the original code here

Fo those using Oxy Ultimate Woo Cart component, this is a snippet to change the text on the checkout button to anything you need. This is courtesy of the developer and work perfectly, see original here

Remove the Gutenberg block library CSS and global styles from the WordPress front end on classic sites, with a config for what to keep.

Quite simply add this near the apply_filters or do_action.

Make WordPress save every uploaded file with a lowercase file name, or only images, so URLs stay consistent on case-sensitive servers.

Oxygen page builder Image element does provide the feature to insert an Image-type custom field’s Alt text using the dynamic data. but if you need overwrite then see 2nd option. Step for show alt tag for image. Ensure that your Image field’s Return Format is set to Image Array in your ACF field group. Step 2 Option 1 Option…

Make the WordPress search match the post title only, not the content, on the front-end search page; wp-admin and other queries keep the normal search.

Sometimes you have a situation where you want the customer to log in, like a donation page, but you don’t want them to end up at /my-account/ but rather be taken back to the page where they were when they started. This code is useful for donation sites, as well as refer a friend scenarios.

Add a Copy button to every code block on your WordPress site with plain CSS and JavaScript: Clipboard API, http fallback, keyboard accessible.

Send WordPress users to the home page after they log out, instead of the login screen, with the logout_redirect filter.

Set the theme-color meta tag in WordPress so mobile browsers paint their address bar and top of the screen in your brand colour.

Show a red WordPress admin notice on every screen while “Discourage search engines from indexing this site” is ticked, so a live site is not left hidden.

Make every published post of a WordPress custom post type private automatically, while drafts, trash and other post types work as usual.

A WordPress reading time shortcode that counts the raw post words, skips blocks and shortcodes, and works in content and templates.

Add an Image column with the featured image to the WordPress admin lists of posts, pages and custom post types, without an extra image size.

Two WooCommerce shortcodes that show the cart total or item count anywhere in WordPress and update without a reload when products are added.

Exclude WordPress post types and taxonomies from the Slim SEO sitemap.xml with two filters, for helper post types nobody should find.

Are you Curious how to remove the slug of a custom post type in WordPress? If you’re using CPT UI, there’s an option called With Front but that doesn’t always seem to work. Follow this tutorial, add these two simple functions and the slug will be removed from your custom post type URL. Note –…

Remove the Category:, Tag:, Author: and Archives: prefix from WordPress archive titles with one filter, and keep it where you still want it.
3rd party plugins actions admin admin bar archive block-themes block editor Blocks block theme build caching capabilities core CSS custom post types development filters gutenberg hook hooks Image img javascript load styles maintenance media Must Have npm Oxygen performance php plugins rest api scripts organizer security single product tailwind theme.json Tips transients updates WooCommerce wordpress wp-cli WP Admin