Skip to main content

Debugging Custom Code (OLS)

warning

Never debug by "trying random edits" on production. Use staging, keep Git history, and keep a rollback command ready.

When to Use This Page

Debug layerWhat to checkTool
Theme stateactive child theme + parent linkWP-CLI
PHP errorsfatals/warningsOLS error log
Cachestale HTML/CSSLSCache purge
Hooks/filterswrong hook or conditiongrep + test markers
Plugin conflictsconflicting outputstaged deactivation

What This Flow Covers

  • Most issues are simple but hidden by caching.
  • A repeatable workflow reduces time-to-fix.
  • Rollback is a key part of debugging.

Diagnostic Flow

flowchart TD
A[Confirm active theme + parent link] --> B[Check OLS + WP debug logs]
B --> C[Disable cache and re-test logged-out]
C --> D[Add a temporary marker to confirm hooks]
D --> E[Isolate changes by diff/commit]
E --> F[Roll back if needed]

Step 1: Confirm Active Theme

confirm-theme-state.sh
cd /var/www/html
wp option get stylesheet
wp option get template

Step 2: Check Common Log Paths

check-ols-logs.sh
ls -lah /usr/local/lsws/logs 2>/dev/null | head -n 40 || true

Step 3: Enable WP Debug Logging (Staging)

In wp-config.php:

wp-config.php
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Then check:

check-wp-debug-log.sh
cd /var/www/html
ls -lah wp-content/debug.log 2>/dev/null || true

Step 4: Add a Temporary Marker to Confirm Hook Runs

wp-content/themes/generatepress-child/inc/hooks.php
<?php

add_action( 'wp_footer', function() {
echo '<!-- debug marker: footer hook ran -->';
} );

Prevention Checklist

PracticeWhy
Debug on stagingProtect production
Keep changes small per commitEasier isolation
Use markers and grepFaster diagnosis
Roll back first, then fixUptime

Issue Matrix

SymptomCauseFix
Admin sees different outputCache varianceTest logged-out and purge LSCache
Fatal errorSyntax or missing fileCheck logs and restore previous version
Hook runs twiceDuplicate add_actionSearch for duplicates
Template override ignoredWrong pathMirror parent path exactly
Output only changes after refreshCachePurge LSCache and test in a private window

Recovery Steps

  1. Add one hook marker comment.
  2. Confirm it appears in page source.
  3. Remove it and confirm rollback.
  4. Enable debug logging on staging and confirm logs are written.

Quick Reference

debug-cheatsheet.sh
cd /var/www/html
wp option get stylesheet
ls -lah /usr/local/lsws/logs 2>/dev/null | head

What's Next