• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP Bitz

A curated collection of code snippets for WordPress

  • Home
  • About
  • Blog
  • Code Snippets
You are here: Home / Archives for Code Snippets

Disable author archives in WordPress

November 2, 2021

// Redirect author page requests. add_action( 'template_redirect', function() { global $wp_query; if ( isset( $_GET['author'] ) …

Continue Reading

Extract data attributes from WooCommerce html tag

August 4, 2021

/** * Extraction utility to get attributes from an HTML tag. * * Example given defaults to WooCommerce "data-" attributes, but you …

Continue Reading

Add additional scheduling options to WordPress

July 19, 2021

add_filter( 'cron_schedules', 'my_add_intervals' ); function my_add_intervals( $schedules ) { // Add a weekly …

Continue Reading

Block access to wp-admin

July 19, 2021

// Blocks access to /wp-admin/ for any user without the identified capability (edit_options=administrator) add_action( 'init', …

Continue Reading

Delete orphaned post meta

July 8, 2021

DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL …

Continue Reading

Get a list of orphaned post meta

July 8, 2021

SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL …

Continue Reading

Get email domain from a user’s email

April 15, 2021

// Verbose example to show steps: $user_email = "example@domain.com"; $email_array = explode( "@", $user_email ); $email_domain = …

Continue Reading

Restrict all site access to a specific IP address

November 9, 2020

add_action( 'init', function() { $ip = ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) ? $_SERVER['HTTP_CLIENT_IP'] : …

Continue Reading

Override the WP random password generator with custom generator

November 9, 2020

// Override the WP random password generator with a custom random password. add_filter( 'random_password', 'my_random_password' ); …

Continue Reading

  • « Go to Previous Page
  • Page 1
  • Page 2
  • Page 3
  • Page 4
  • Page 5
  • Interim pages omitted …
  • Page 7
  • Go to Next Page »

Primary Sidebar

Join for free!

Get free code snippets, WordPress best practices, and practical Content Marketing advice from seasoned WordPress expert Chad Butler (butlerblog):

Recent Posts

  • Check and delete orphaned user meta in WordPress
  • Add a Database Connection to use WPDB
  • Notice: Function WP_Block_Patterns_Registry::register was called incorrectly
  • Use WP-CLI to back up your site
  • Bitnami WordPress Autoptimize cannot write to the cache directory

Copyright © 2026 · Maker Pro on Genesis Framework · WordPress · Log in