DeveloperBreeze

WordPress Cheatsheet

1. General Information

  • WordPress Version:

bloginfo('version');
  

  • Site URL:

bloginfo('url');
  

  • Site Name:

bloginfo('name');
  

  • Admin Email:

get_option('admin_email');
  

  • Theme Directory:

bloginfo('template_directory');
  

2. Template Tags

  • Header:

get_header();
  

  • Footer:

get_footer();
  

  • Sidebar:

get_sidebar();
  

  • Search Form:

get_search_form();
  

  • Post Content:

the_content();
  

  • Post Title:

the_title();
  

  • Post Excerpt:

the_excerpt();
  

  • Post Thumbnail:

the_post_thumbnail('thumbnail');
  

  • Permalink:

the_permalink();
  

  • Author Name:

the_author();
  

  • Author Posts URL:

the_author_posts_link();
  

  • Post Date:

the_date();
  

3. Querying Posts

  • Custom Query:

$query = new WP_Query(array(
      'post_type' => 'post',
      'posts_per_page' => 5
  ));
  
  if ($query->have_posts()) : 
      while ($query->have_posts()) : $query->the_post();
          // Loop content
      endwhile;
      wp_reset_postdata();
  endif;
  

  • Loop through Posts:

if (have_posts()) : 
      while (have_posts()) : the_post();
          // Loop content
      endwhile;
  endif;
  

4. Working with Menus

  • Register a Menu:

function register_my_menu() {
      register_nav_menu('header-menu', __('Header Menu'));
  }
  add_action('init', 'register_my_menu');
  

  • Display a Menu:

wp_nav_menu(array(
      'theme_location' => 'header-menu'
  ));
  

5. Widgets

  • Register a Widget Area:

function my_widgets_init() {
      register_sidebar(array(
          'name' => 'Sidebar Widget Area',
          'id' => 'sidebar-1',
          'before_widget' => '<div class="widget">',
          'after_widget' => '</div>',
          'before_title' => '<h3 class="widget-title">',
          'after_title' => '</h3>',
      ));
  }
  add_action('widgets_init', 'my_widgets_init');
  

  • Display a Widget Area:

if (is_active_sidebar('sidebar-1')) {
      dynamic_sidebar('sidebar-1');
  }
  

6. Custom Post Types

  • Register a Custom Post Type:

function create_post_type() {
      register_post_type('movies',
          array(
              'labels' => array(
                  'name' => __('Movies'),
                  'singular_name' => __('Movie')
              ),
              'public' => true,
              'has_archive' => true,
              'rewrite' => array('slug' => 'movies'),
              'supports' => array('title', 'editor', 'thumbnail')
          )
      );
  }
  add_action('init', 'create_post_type');
  

7. Custom Taxonomies

  • Register a Custom Taxonomy:

function create_movie_taxonomy() {
      register_taxonomy(
          'genre',
          'movies',
          array(
              'label' => __('Genre'),
              'rewrite' => array('slug' => 'genre'),
              'hierarchical' => true,
          )
      );
  }
  add_action('init', 'create_movie_taxonomy');
  

8. Shortcodes

  • Create a Shortcode:

function my_shortcode_function() {
      return 'Hello, this is a shortcode!';
  }
  add_shortcode('myshortcode', 'my_shortcode_function');
  

  • Use a Shortcode:

echo do_shortcode('[myshortcode]');
  

9. Actions and Filters

  • Adding an Action:

function my_custom_action() {
      // Action logic
  }
  add_action('wp_footer', 'my_custom_action');
  

  • Adding a Filter:

function my_custom_filter($content) {
      return $content . ' Extra content added by filter!';
  }
  add_filter('the_content', 'my_custom_filter');
  

10. Enqueueing Scripts and Styles

  • Enqueue a Script:

function my_custom_scripts() {
      wp_enqueue_script('custom-script', get_template_directory_uri() . '/js/custom-script.js', array('jquery'), null, true);
  }
  add_action('wp_enqueue_scripts', 'my_custom_scripts');
  

  • Enqueue a Style:

function my_custom_styles() {
      wp_enqueue_style('custom-style', get_template_directory_uri() . '/css/custom-style.css');
  }
  add_action('wp_enqueue_scripts', 'my_custom_styles');
  

11. User Management

  • Get Current User:

$current_user = wp_get_current_user();
  echo 'Username: ' . $current_user->user_login;
  

  • Check User Role:

if (current_user_can('administrator')) {
      // Do something for admins
  }
  

12. Security

  • Escape Output:

echo esc_html($data);
  

  • Sanitize Input:

$sanitized_data = sanitize_text_field($_POST['data']);
  

  • Nonces:

wp_nonce_field('my_action', 'my_nonce');
  
  if (!isset($_POST['my_nonce']) || !wp_verify_nonce($_POST['my_nonce'], 'my_action')) {
      // Nonce check failed
  }
  

13. Useful Commands

  • WordPress CLI Install:

wp core install --url="example.com" --title="Example Site" --admin_user="admin" --admin_password="password" --admin_email="you@example.com"
  

  • List Plugins:

wp plugin list
  

  • Activate Plugin:

wp plugin activate plugin-name
  

  • Update WordPress Core:

wp core update
  

  • Update Plugins:

wp plugin update --all
  

14. Debugging

  • Enable Debugging:

Add to wp-config.php:

define('WP_DEBUG', true);
  define('WP_DEBUG_LOG', true);
  define('WP_DEBUG_DISPLAY', false);
  

  • View Debug Log:

error_log('Debug message');
  

15. Customizer API

  • Add Customizer Setting:

function my_custom_customizer($wp_customize) {
      $wp_customize->add_setting('my_setting', array(
          'default' => 'Default Value',
      ));
      $wp_customize->add_control('my_setting', array(
          'label' => __('My Setting', 'textdomain'),
          'section' => 'title_tagline',
          'type' => 'text',
      ));
  }
  add_action('customize_register', 'my_custom_customizer');
  

16. WooCommerce Integration

  • Check if WooCommerce is Active:

if (class_exists('WooCommerce')) {
      // WooCommerce is active
  }
  

  • Add Product to Cart:

WC()->cart->add_to_cart($product_id);
  

  • Get Cart Total:

echo WC()->cart->get_cart_total();
  

---

This WordPress cheatsheet should serve as a quick reference guide for WordPress developers. Whether you're working on themes, plugins, or custom solutions, these snippets will help you with common tasks and functions.

Continue Reading

Discover more amazing content handpicked just for you

Tutorial

How to Stop SSH From Timing Out

ClientAliveInterval 60
ClientAliveCountMax 3

This makes the server send a keep-alive packet every 60 seconds, allowing up to 3 missed replies before disconnecting.

Aug 21, 2025
Read More
Tutorial

How to Translate URLs in React (2025 Guide)

Sample fr.json:

{
  "routes": {
    "home": "accueil",
    "about": "a-propos"
  },
  "title": "Bienvenue sur notre site !"
}

May 04, 2025
Read More
Tutorial

Globalization in React (2025 Trends & Best Practices)

const today = new Intl.DateTimeFormat(i18n.language).format(new Date());
new Intl.NumberFormat('en-US', {
  style: 'currency',
  currency: 'USD'
}).format(4999.99);

// Output: $4,999.99

May 04, 2025
Read More
Tutorial

Implementing Internationalization (i18n) in a Large React Application (2025 Guide)

Use localStorage via i18next-browser-languagedetector:

detection: {
  order: ['localStorage', 'navigator', 'htmlTag'],
  caches: ['localStorage'],
}

May 04, 2025
Read More
Tutorial

Building Micro-Frontends with Webpack Module Federation (2025 Guide)

npm init vue@latest
cd analytics-app
npm install

Install dependencies for Webpack configuration:

May 04, 2025
Read More
Tutorial

State Management Beyond Redux: Using Zustand for Scalable React Apps

   import create from 'zustand';

   const useStore = create((set) => ({
     count: 0,
     increase: () => set((state) => ({ count: state.count + 1 })),
     decrease: () => set((state) => ({ count: state.count - 1 })),
   }));
   import React from 'react';
   import useStore from './store';

   function Counter() {
     const { count, increase, decrease } = useStore();
     return (
       <div>
         <h1>{count}</h1>
         <button onClick={increase}>Increase</button>
         <button onClick={decrease}>Decrease</button>
       </div>
     );
   }

   export default Counter;

May 03, 2025
Read More
Tutorial

Mastering React Rendering Performance with Memoization and Context

import React, { useState, useMemo } from 'react';

function ExpensiveComponent({ data }) {
  const processedData = useMemo(() => {
    // Expensive computation
    return data.map(item => /* processing */ item);
  }, [data]);

  return <div>{/* render processedData */}</div>;
}

This approach ensures that the expensive computation runs only when data changes, improving performance.

May 03, 2025
Read More
Tutorial

✅ How to Disable MySQL Password Validation on Ubuntu 25.04

UNINSTALL COMPONENT 'file://component_validate_password';

If successful, you'll see:

May 01, 2025
Read More
Tutorial

How to Move the MySQL Data Directory to a New Location on Ubuntu 25.04

sudo systemctl stop mysql

Choose your new location, for example /mnt/data/mysql, and move the current data:

May 01, 2025
Read More
Tutorial

How to Install PHP, MySQL, and phpMyAdmin on Ubuntu 25.04 (LAMP Stack Setup Guide)

sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl

During installation:

May 01, 2025
Read More
Tutorial

How to Fix NVIDIA Driver Issues on Ubuntu (Dell Vostro 3521)

✅ This means your system has both Intel integrated graphics and an NVIDIA discrete GPU.

Install Mesa utilities:

Apr 14, 2025
Read More
Cheatsheet

ShadCN Cheatsheet

Example:

npx shadcn-ui@latest add button
npx shadcn-ui@latest add card
npx shadcn-ui@latest add input

Apr 12, 2025
Read More
Tutorial

Avoiding Memory Leaks in C++ Without Smart Pointers

Some legacy APIs require raw pointers. You can still use get():

void legacyFunction(char* data);

void useLegacyAPI() {
    ScopedArray<char> buffer(new char[512]);
    legacyFunction(buffer.get());
}

Apr 11, 2025
Read More
Tutorial

Deep Copy in C++: How to Avoid Shallow Copy Pitfalls

This is the Rule of Five. Add move semantics if your class is performance-sensitive and uses resource ownership.

When your class uses raw pointers:

Apr 11, 2025
Read More
Tutorial

🛡️ Protect Your Forms Like a Pro: Anti-Spam Techniques That Actually Work

So your goal isn’t to annoy humans, it’s to trip up bots.

A honeypot is a hidden form field that users don’t see, but bots do. If the field is filled, you know it’s a bot.

Apr 04, 2025
Read More
Tutorial

Build a Custom Rate Limiter in Node.js with Redis

  • Offer different limits for free vs paid users
  • Log or monitor usage per user

This isn’t just a quick fix—it’s a deep dive into:

Apr 04, 2025
Read More
Tutorial
javascript

Building a Real-Time Object Detection Web App with TensorFlow.js and p5.js

This guide will walk you through setting up your development environment, loading a pre-trained model, capturing video input, and overlaying detection results on the video feed.

Before you begin, make sure you have the following installed and set up:

Feb 12, 2025
Read More
Tutorial

Building a Cross-Platform Desktop App with Tauri and Svelte: A Step-by-Step Tutorial

To install the Tauri CLI globally, run:

npm install -g @tauri-apps/cli

Feb 12, 2025
Read More
Tutorial

Implementing a Domain-Specific Language (DSL) with LLVM and C++

Later, you can extend it to include variables, functions, or even control flow constructs.

Example DSL Code:

Feb 12, 2025
Read More
Cheatsheet
css html

Grids Cheatsheet

No preview available for this content.

Jan 14, 2025
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!