• 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

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

Restrict WordPress login by IP address

October 1, 2020

/** * The following will restrict login to a * specific IP address. * * Change "111.111.111.111" to the actual IP. */ add_action( …

Continue Reading

Add cc and bcc to wp_mail() headers

September 28, 2020

$headers[] = 'From: Some One '; $headers[] = 'Cc: cc_number_1@email.com'; $headers[] = 'Cc: cc_number_2@email.com'; $headers[] = …

Continue Reading

Random Number Generator

September 4, 2020

/** * Generates a random number of a fixed number of digits. * * The use of STR_PAD_LEFT allows the result to ALWAYS be the given …

Continue Reading

Remove WP emoji scripts from header

July 12, 2020

/** * This snippet removes the WP emoji code from the WP header. */ remove_action( 'wp_head', …

Continue Reading

  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • 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

  • Block an IP address from accessing your site
  • Using WordPress Debug Constants
  • Save WordPress debug log by date
  • Utility function for the WordPress error log
  • How to Create a Site Specific Plugin

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