Introduction to WordPress Architecture

John
15 min read

What is WordPress?

WordPress is a Content Management System (CMS) - a software application that allows you to create, manage, and publish digital content (websites, blogs, applications) without writing code from scratch every time.

Think of WordPress as the engine of a car. Just as you don't need to build an engine to drive a car, you don't need to build a CMS from scratch to create a website. WordPress provides the foundation, and you customize it to meet your specific needs.

Key Statistics

  • Powers 43%+ of all websites on the internet
  • Open-source and free to use
  • Written primarily in PHP
  • Uses MySQL or MariaDB for data storage
  • Highly extensible through themes and plugins

WordPress Architecture Overview

WordPress follows a traditional LAMP/LEMP stack architecture:

┌─────────────────────────────────────────────────────────────┐
│                         USER BROWSER                        │
│                     (Chrome, Firefox, etc.)                 │
└──────────────────────────┬──────────────────────────────────┘
                           │ HTTP/HTTPS Request
                           ▼
┌─────────────────────────────────────────────────────────────┐
│                     WEB SERVER LAYER                        │
│              (Apache, Nginx, LiteSpeed)                     │
│  - Receives HTTP requests                                   │
│  - Serves static files (images, CSS, JS)                    │
│  - Forwards dynamic requests to PHP                         │
└──────────────────────────┬──────────────────────────────────┘
                           │ PHP Processing
                           ▼
┌─────────────────────────────────────────────────────────────┐
│                    PHP PROCESSOR LAYER                      │
│                      (PHP-FPM, mod_php)                     │
│  - Executes WordPress PHP code                              │
│  - Processes business logic                                 │
│  - Generates HTML output                                    │
└──────────────────────────┬──────────────────────────────────┘
                           │ Database Queries
                           ▼
┌─────────────────────────────────────────────────────────────┐
│                    DATABASE LAYER                           │
│                   (MySQL, MariaDB)                          │
│  - Stores all content, settings, user data                  │
│  - Executes queries and returns results                     │
└─────────────────────────────────────────────────────────────┘

Component Breakdown

Web Server: The gatekeeper that receives requests from users' browsers and decides what to do with them.

PHP Processor: The brain that executes WordPress code and generates dynamic content.

Database: The storage vault where all your content, settings, and user information live.

Request Lifecycle

Understanding how WordPress processes a single page request is crucial for optimization:

1. User Enters URL
   ↓
2. Browser Sends HTTP Request
   ↓
3. Web Server Receives Request
   ↓
4. Web Server Checks for Static Files
   ├─ If static (image, CSS, JS) → Serve directly → END
   └─ If dynamic (PHP) → Continue
   ↓
5. Web Server Forwards to PHP Processor
   ↓
6. WordPress Core Loads (wp-config.php, wp-settings.php)
   ↓
7. WordPress Initializes
   ├─ Load configuration
   ├─ Connect to database
   ├─ Load active theme
   ├─ Load active plugins
   └─ Initialize hooks system
   ↓
8. Query Parsing
   ├─ Determine what content is being requested
   └─ Build database query
   ↓
9. Database Queries Executed
   ├─ Fetch posts, pages, metadata
   └─ Return results to PHP
   ↓
10. Template Selection
    ├─ WordPress determines which template to use
    └─ Load appropriate theme file
    ↓
11. Content Rendering
    ├─ Execute template PHP code
    ├─ Apply filters and actions
    └─ Generate final HTML
    ↓
12. Output Buffer Sent to Browser
    ↓
13. Browser Renders Page
    ↓
14. Browser Requests Additional Assets (CSS, JS, Images)
    ↓
15. Page Fully Loaded

Performance Insight: Each step adds latency. Optimization focuses on:

  • Reducing database queries (step 9)
  • Caching rendered output (skip steps 6-11)
  • Optimizing asset delivery (step 14)
  • Using CDNs to serve static files faster

WordPress Core Components

1. WordPress Core Files

The WordPress core is the foundation - the essential files that make WordPress work.

Key Core Files:

File/DirectoryPurpose
wp-config.phpMain configuration file (database credentials, security keys)
wp-settings.phpInitializes WordPress environment and loads core
wp-load.phpLoads WordPress environment
wp-blog-header.phpTemplate loading process
/wp-admin/Administration dashboard files
/wp-includes/Core WordPress libraries and functions
/wp-content/Your customizations (themes, plugins, uploads)

Important Rule: Never modify WordPress core files. They get overwritten during updates.

2. Themes

A theme controls how your WordPress site looks and is presented to visitors.

wp-content/themes/your-theme/
├── style.css              # Main stylesheet + theme metadata
├── functions.php          # Theme functionality and features
├── index.php             # Default template file
├── header.php            # Header template
├── footer.php            # Footer template
├── sidebar.php           # Sidebar template
├── single.php            # Single post template
├── page.php              # Single page template
├── archive.php           # Archive listing template
├── search.php            # Search results template
├── 404.php               # Not found template
└── /assets/              # CSS, JS, images, fonts
    ├── /css/
    ├── /js/
    └── /images/

Anatomy of a Theme:

  • Required: style.css (with header metadata) and index.php
  • Templates: PHP files that control different page types
  • Template Parts: Reusable components (header, footer, sidebar)
  • Assets: Stylesheets, JavaScript, images, fonts

3. Plugins

A plugin extends WordPress functionality without modifying core files.

wp-content/plugins/your-plugin/
├── your-plugin.php       # Main plugin file with metadata
├── includes/             # Core functionality
│   ├── class-admin.php
│   ├── class-frontend.php
│   └── functions.php
├── admin/                # Admin interface files
│   ├── settings.php
│   └── /css/
├── public/               # Frontend files
│   ├── /css/
│   └── /js/
└── languages/            # Translation files

Plugin vs Theme:

  • Themes: Presentation and display
  • Plugins: Functionality and features
  • Rule of thumb: If it's about appearance → Theme. If it's about functionality → Plugin.

4. Database Structure

WordPress stores all data in a MySQL/MariaDB database with a default of 12 tables:

WordPress Database Structure
═════════════════════════════════════════════════════

Core Tables (12 default):
┌─────────────────────┬────────────────────────────────────┐
│ Table Name          │ Purpose                            │
├─────────────────────┼────────────────────────────────────┤
│ wp_posts            │ Posts, pages, custom post types    │
│ wp_postmeta         │ Post metadata (custom fields)      │
│ wp_comments         │ Comments on posts                  │
│ wp_commentmeta      │ Comment metadata                   │
│ wp_users            │ User account information           │
│ wp_usermeta         │ User metadata (preferences, roles) │
│ wp_terms            │ Categories, tags, taxonomy terms   │
│ wp_term_taxonomy    │ Relationship between terms/taxs    │
│ wp_term_relationships│ Links posts to terms              │
│ wp_options          │ Site settings and configuration    │
│ wp_links            │ Blogroll links (legacy)            │
│ wp_termmeta         │ Term metadata                      │
└─────────────────────┴────────────────────────────────────┘

Table Prefix: wp_ is default but should be changed for security.

Most Important Tables:

  • wp_posts: Contains all content (posts, pages, attachments, custom post types)
  • wp_options: Site configuration, plugin settings, theme options
  • wp_postmeta: Custom fields attached to posts
  • wp_users: User accounts and authentication data

The WordPress Hierarchy

WordPress uses a template hierarchy - a system that determines which template file to use for different types of content.

Template Hierarchy (Simplified)
═════════════════════════════════════════════════════

Homepage Request:
front-page.php → home.php → index.php

Single Post:
single-{post-type}-{slug}.php → single-{post-type}.php → single.php → singular.php → index.php

Page:
page-{slug}.php → page-{id}.php → page.php → singular.php → index.php

Category Archive:
category-{slug}.php → category-{id}.php → category.php → archive.php → index.php

Custom Post Type Archive:
archive-{post-type}.php → archive.php → index.php

Search:
search.php → index.php

404 Error:
404.php → index.php

Fallback System: WordPress moves right to left until it finds a template that exists. index.php is the ultimate fallback.

WordPress Execution Flow

When a WordPress page loads, here's what happens internally:

1. BOOTSTRAP PHASE
   ├─ Load wp-config.php (database credentials, constants)
   ├─ Load wp-settings.php (WordPress environment)
   └─ Connect to database

2. INITIALIZATION PHASE
   ├─ Load activated plugins (in order)
   ├─ Load active theme's functions.php
   ├─ Initialize hooks system
   └─ Set up WordPress environment

3. PARSING PHASE
   ├─ Parse request URL
   ├─ Determine query variables
   └─ Set up main query

4. QUERY PHASE
   ├─ Build SQL query based on request
   ├─ Execute database query
   └─ Store results in global $wp_query

5. TEMPLATE LOADING PHASE
   ├─ Determine template based on hierarchy
   ├─ Load template file
   └─ Execute template PHP code

6. RENDERING PHASE
   ├─ Generate HTML output
   ├─ Apply filters and actions
   └─ Send output to browser

7. SHUTDOWN PHASE
   ├─ Execute shutdown hooks
   ├─ Clean up resources
   └─ Close database connection

WordPress Hook System

Actions (Do Something)

Actions let you execute custom code at specific points during WordPress execution.

// WordPress fires an action
do_action('init');

// Your code listens for that action
add_action('init', 'your_custom_function');

function your_custom_function() {
    // Your code runs when 'init' action fires
}

Think of actions as announcements: "Hey, initialization just finished!" and your code responds: "Great, let me do something now!"

Filters (Modify Something)

Filters let you modify data before WordPress uses it.

// WordPress applies a filter to content
$content = apply_filters('the_content', $content);

// Your code modifies the content
add_filter('the_content', 'your_modification_function');

function your_modification_function($content) {
    // Modify $content here
    return $content; // Must return the modified value
}

Think of filters as checkpoints: Data passes through, and your code can modify it before it continues.

Key Difference:

  • Actions: Execute code (e.g., send email, log event)
  • Filters: Modify and return data (e.g., change post title, modify query)

WordPress APIs

WordPress provides several APIs (Application Programming Interfaces) - sets of functions for common tasks:

APIPurposeExample Use
Plugin APIHooks system for actions/filtersExtend functionality
Database APIInteract with database safely$wpdb->get_results()
Options APIStore/retrieve settingsget_option(), update_option()
Transients APICache data temporarilyset_transient(), get_transient()
HTTP APIMake HTTP requestswp_remote_get(), wp_remote_post()
Filesystem APIRead/write filesWP_Filesystem()
Settings APICreate settings pagesRegister settings, sections, fields
REST APIExpose WordPress data via HTTP/wp-json/wp/v2/posts
Rewrite APICustom URL structuresPretty permalinks, custom endpoints

Why Use WordPress APIs?

  • Security: Built-in sanitization and validation
  • Compatibility: Works across different server environments
  • Updates: Won't break when WordPress updates
  • Best Practices: Follow WordPress coding standards

Performance Considerations in Architecture

Where Performance is Lost

Request Processing Time Breakdown (Typical WordPress Site):
═════════════════════════════════════════════════════════════

Database Queries:           ████████████████░░░░ 40%
PHP Processing:             ████████████░░░░░░░░ 30%
External HTTP Requests:     ██████░░░░░░░░░░░░░░ 15%
File I/O Operations:        ████░░░░░░░░░░░░░░░░ 10%
Template Rendering:         ██░░░░░░░░░░░░░░░░░░  5%

Optimization Strategies

At Each Layer:

  1. Web Server Layer

    • Enable HTTP/2 or HTTP/3
    • Configure compression (Gzip/Brotli)
    • Implement page caching
    • Serve static files directly
  2. PHP Layer

    • Use latest PHP version (8.0+)
    • Enable OPcache
    • Implement object caching (Redis/Memcached)
    • Optimize code and reduce plugin count
  3. Database Layer

    • Optimize queries (use indexes)
    • Implement query caching
    • Clean up post revisions and transients
    • Use read replicas for heavy traffic
  4. Application Layer

    • Minimize HTTP requests
    • Lazy load images
    • Defer/async JavaScript
    • Minify CSS/JS
    • Use CDN for static assets

WordPress vs. Traditional Frameworks

Comparison

AspectWordPressLaravel/Symfony
Learning CurveGentleSteep
Development SpeedFast (built-in features)Slower (build from scratch)
FlexibilityHigh with hooksVery high
Performance (default)ModerateHigh
Performance (optimized)Very HighVery High
Community/PluginsMassiveGrowing
Use CaseContent sites, blogs, small-medium appsComplex applications
HostingWidely availableMay need specific setup

When to Choose WordPress:

  • Content-heavy websites
  • Quick time-to-market needed
  • Non-technical users will manage content
  • Large ecosystem of plugins needed
  • Budget-conscious projects

When Not to Choose WordPress:

  • Real-time applications
  • Highly custom application logic
  • Microservices architecture
  • When you need full control over everything

Key Takeaways

  1. WordPress is a CMS: It provides structure for managing content, not just building websites.

  2. Layered Architecture: Web Server → PHP → Database. Each layer can be optimized independently.

  3. Hook-Driven: Actions and filters allow extending WordPress without modifying core.

  4. Template Hierarchy: WordPress automatically selects templates based on content type.

  5. Performance Matters: Default WordPress needs optimization for high-traffic sites.

  6. Don't Modify Core: Always use themes, plugins, and hooks for customization.

  7. APIs Provide Safety: Use WordPress APIs instead of direct database access or file operations.