• 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

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

Get user role

October 21, 2020

/** * Gets WordPress user role. * * @see: https://core.trac.wordpress.org/ticket/22624 * @see: …

Continue Reading

Promote your RSS feed on every post

October 21, 2020

/* * This demo uses the_content filter to add an RSS * link to the end of every post. * * @uses the_content * @uses is_single() …

Continue Reading

MySQL UPDATE and REPLACE

October 6, 2020

UPDATE wp_posts SET post_content = REPLACE( post_content, 'http://mysite.com', 'https://mysite.com' ), guid = REPLACE( guid, …

Continue Reading

  • « Go to Previous Page
  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Go to page 5
  • Go to page 6
  • 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

  • Bitnami WordPress Autoptimize cannot write to the cache directory
  • Create and delete WordPress sites in XAMPP with a batch file
  • How to fix “Error: MySQL Shutdown Unexpectedly” in XAMPP control panel
  • Fix missing Customizer in WordPress 6
  • Use Proofy.io API to validate WordPress registrations

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