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

Edit the SSH daemon config:

sudo nano /etc/ssh/sshd_config

Aug 21, 2025
Read More
Tutorial

How to Translate URLs in React (2025 Guide)

npm install react-router-dom i18next react-i18next i18next-browser-languagedetector
/src
  /locales
    en.json
    fr.json
  /pages
    Home.js
    About.js
  i18n.js
  App.js
  routes.js

May 04, 2025
Read More
Tutorial

Globalization in React (2025 Trends & Best Practices)

With mobile-first usage in emerging markets:

  • Ensure localized content fits small screens
  • Test RTL support on all breakpoints
  • Use dynamic font scaling for languages like Arabic or Hindi
  • Translate push notifications and in-app messages

May 04, 2025
Read More
Tutorial

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

import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';

// Import translation files
import en from './locales/en.json';
import fr from './locales/fr.json';

i18n
  .use(LanguageDetector) // Detects user language
  .use(initReactI18next)
  .init({
    resources: {
      en: { translation: en },
      fr: { translation: fr },
    },
    fallbackLng: 'en',
    interpolation: {
      escapeValue: false, // React already escapes
    },
    detection: {
      order: ['localStorage', 'navigator', 'htmlTag'],
      caches: ['localStorage'],
    },
  });

export default i18n;

Create folder structure:

May 04, 2025
Read More
Tutorial

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

Let’s say you’re building a dashboard app in React, but your analytics module is handled by another team using Vue. You don’t want to tightly couple the two.

With Webpack Module Federation, you can load the Vue-based analytics micro-frontend into the React host — all without bundling it directly.

May 04, 2025
Read More
Tutorial

State Management Beyond Redux: Using Zustand for Scalable React Apps

Zustand is a small, fast, and scalable state management solution for React applications. Developed by the creators of Jotai and React-spring, Zustand aims to provide a minimalistic API based on hooks, eliminating the need for boilerplate code and context providers.

Key Features:

May 03, 2025
Read More
Tutorial

Mastering React Rendering Performance with Memoization and Context

   const increment = useCallback(() => setCount(c => c + 1), []);

Implementing these practices ensures that only components dependent on specific context values re-render when those values change.([Medium][7])

May 03, 2025
Read More
Tutorial

✅ How to Disable MySQL Password Validation on Ubuntu 25.04

CREATE USER 'devuser'@'localhost' IDENTIFIED BY '123';
GRANT ALL PRIVILEGES ON *.* TO 'devuser'@'localhost';
FLUSH PRIVILEGES;

This should now work without any errors.

May 01, 2025
Read More
Tutorial

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

sudo systemctl start mysql

Check that MySQL is using the new path:

May 01, 2025
Read More
Tutorial

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

This script will prompt you to set a root password, remove anonymous users, disallow remote root login, remove the test database, and reload privilege tables.

Install phpMyAdmin along with necessary PHP extensions:

May 01, 2025
Read More
Tutorial

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

Paste:

#!/bin/bash
__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia __GL_VRR_ALLOWED=0 "$@"

Apr 14, 2025
Read More
Cheatsheet

ShadCN Cheatsheet

npm install --save-dev @testing-library/react @testing-library/jest-dom
components/
│
├── ui/           # All ShadCN UI components
│   ├── button.tsx
│   ├── card.tsx
│   └── ...
├── shared/       # Your own custom UI components
├── layout/       # Layout wrappers

Apr 12, 2025
Read More
Tutorial

Avoiding Memory Leaks in C++ Without Smart Pointers

void loadData() {
    char* buffer = new char[1024];
    // some processing...
    if (someCondition()) {
        return; // leak!
    }
    delete[] buffer;
}

What’s wrong? If someCondition() returns true, buffer is never deallocated.

Apr 11, 2025
Read More
Tutorial

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

Shallow a(10);
Shallow b = a;  // default copy constructor

This causes both a.data and b.data to point to the same memory. When both destructors run, delete is called twice on the same pointer — undefined behavior!

Apr 11, 2025
Read More
Tutorial

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

Spam submissions are one of the most common annoyances for web developers. Whether you're dealing with contact forms, login pages, or comment sections—bots will find and abuse them.

In this tutorial, you'll learn real-world, effective anti-spam techniques beyond just slapping on a CAPTCHA. These strategies are easy to implement, and when combined, they make your forms extremely hard to abuse.

Apr 04, 2025
Read More
Tutorial

Build a Custom Rate Limiter in Node.js with Redis

Protect your API from abuse and learn how rate limiting works under the hood.

When developing web apps or APIs, it’s critical to prevent users from overwhelming your server. That’s where rate limiting comes in. In this guide, we’ll build a custom rate limiter in Node.js using Redis—no libraries, no magic, just code you control and understand.

Apr 04, 2025
Read More
Tutorial
javascript

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

Now that you have a basic real-time object detection app, consider extending its functionality:

  • Filtering Detections: Display only specific classes (e.g., only people or vehicles).
  • Custom UI Elements: Use p5.js to add buttons or controls that modify detection settings in real time.
  • Performance Optimization: Experiment with frame rate adjustments or model parameters for faster detection.

Feb 12, 2025
Read More
Tutorial

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

<script>
  let count = 0;
  const increment = () => count += 1;
</script>

<main>
  <h1>Welcome to Tauri + Svelte Desktop App</h1>
  <p>Current count: {count}</p>
  <button on:click={increment}>Increment</button>
</main>

<style>
  main {
    text-align: center;
    padding: 2rem;
    font-family: Arial, sans-serif;
  }
  button {
    margin-top: 1rem;
    padding: 0.5rem 1rem;
    font-size: 1rem;
  }
</style>

This simple component displays a title, a count, and a button to update the count.

Feb 12, 2025
Read More
Tutorial

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

#include "DSL/AST.h"
#include <llvm/IR/Module.h>
#include <llvm/IR/Verifier.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/IR/Function.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/IR/IRBuilder.h>
#include <memory>
#include <iostream>

llvm::Function* generateFunction(llvm::LLVMContext& context, llvm::Module& module, ASTNode* root) {
    // Create function type: double ().
    llvm::FunctionType* funcType = llvm::FunctionType::get(llvm::Type::getDoubleTy(context), false);
    llvm::Function* function = llvm::Function::Create(funcType, llvm::Function::ExternalLinkage, "main_expr", module);

    llvm::BasicBlock* block = llvm::BasicBlock::Create(context, "entry", function);
    llvm::IRBuilder<> builder(block);

    llvm::Value* retVal = root->codegen(builder);
    if (!retVal) {
        std::cerr << "Error generating code for the expression." << std::endl;
        return nullptr;
    }

    builder.CreateRet(retVal);
    if (llvm::verifyFunction(*function, &llvm::errs())) {
        function->eraseFromParent();
        return nullptr;
    }

    return function;
}

void optimizeModule(llvm::Module& module) {
    llvm::legacy::PassManager passManager;
    // Add some basic optimization passes.
    // In a production compiler, you'd add many more!
    passManager.add(llvm::createInstructionCombiningPass());
    passManager.add(llvm::createReassociatePass());
    passManager.add(llvm::createGVNPass());
    passManager.add(llvm::createCFGSimplificationPass());
    passManager.run(module);
}

After generating LLVM IR, we optimize it using LLVM’s pass managers. The above optimizeModule function demonstrates adding a few standard optimization passes. In 2025, you might incorporate cutting-edge passes or even machine learning–based tuning for further enhancements.

Feb 12, 2025
Read More
Cheatsheet
css html

Grids Cheatsheet

<!-- Basic grid container -->
<div class="container">
<div class="container-fluid">                     <!-- Full-width container -->

<!-- Row -->
<div class="row">                                 <!-- Basic row -->
<div class="row g-3">                             <!-- Row with gap -->

<!-- Responsive behavior -->
<div class="row row-cols-1">                      <!-- 1 column -->
<div class="row row-cols-md-2">                   <!-- 2 columns on md screens -->
<div class="row row-cols-lg-3">                   <!-- 3 columns on lg screens -->
<!-- Basic columns -->
<div class="col">                                 <!-- Equal width -->
<div class="col-6">                               <!-- 6/12 width -->
<div class="col-auto">                            <!-- Content-width -->

<!-- Responsive columns -->
<div class="col-sm-6">                           <!-- 6/12 on small screens -->
<div class="col-md-4">                           <!-- 4/12 on medium screens -->
<div class="col-lg-3">                           <!-- 3/12 on large screens -->

<!-- Column ordering -->
<div class="order-1">                            <!-- Order first -->
<div class="order-last">                         <!-- Order last -->

<!-- Offset -->
<div class="offset-md-3">                        <!-- Offset by 3 columns -->

<!-- Alignment -->
<div class="align-self-start">
<div class="align-self-center">
<div class="align-self-end">

Jan 14, 2025
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!