• 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

Add a custom default avatar to WordPress

February 3, 2022

/** * This can be used to apply a custom default avatar to your WordPress * install. Change the $custom_avatar value below to the …

Continue Reading

Get post slug from post ID

January 6, 2022

$post_id = 7; $slug = get_post_field( 'post_name', $post_id ); …

Continue Reading

Horizontal Navigation Menu for WooCommerce My Account Page

January 4, 2022

@media only screen and (min-width: 769px) { .woocommerce-account .woocommerce-MyAccount-content, .woocommerce-account …

Continue Reading

Open “edit” post link in a new tab

January 2, 2022

add_filter( 'post_row_actions', 'tab_row_actions', 10, 2 ); function tab_row_actions( $actions, $post ) { //echo ''; print_r( $actions ); …

Continue Reading

Get order ID, customer shipping and billing information from WooCommerce database (MySQL query)

December 28, 2021

SELECT p.ID as order_id, p.post_date, max( CASE WHEN pm.meta_key = '_billing_email' and p.ID = pm.post_id THEN pm.meta_value …

Continue Reading

Strip “read more” anchor link from content so “read more” opens at the top of the page

December 23, 2021

// Filter to strip anchor link from the content (so "read more" goes to top of page, not anchor location). add_action('the_content', …

Continue Reading

Get an array of variation IDs for a given product ID (all possible variations)

December 22, 2021

$product = wc_get_product( $product_id ); $variation_ids = $product->get_children(); …

Continue Reading

Get an array of variation IDs for a given product ID (visible variations only)

December 22, 2021

$product = wc_get_product( $product_id ); $variations = $product->get_available_variations(); $variation_ids = wp_list_pluck( …

Continue Reading

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

  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Interim pages omitted …
  • 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

  • How to Run WP-CLI on Windows
  • Get an array of variation IDs for a WooCommerce product
  • Check and delete orphaned post meta in WordPress
  • Block an IP address from accessing your site
  • Using WordPress Debug Constants

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