Skip to content

Adding PHP

If you need to add PHP logic (custom hooks, filters, shortcodes, etc.), the safest method is to use the Code Snippets plugin. This keeps your changes update‑safe and easy to manage.

Recommended plugin

Why use Code Snippets

  • No theme files edited
  • Easy enable/disable per snippet
  • Update‑safe
  • Great for quick customizations

How to add a snippet

  1. Install and activate Code Snippets
  2. Go to Snippets → Add New
  3. Paste your PHP code
  4. Choose where it should run (front end, admin, everywhere)
  5. Save and activate

Example: Add a custom body class

<?php
add_filter('body_class', function ($classes) {
    $classes[] = 'custom-site-class';
    return $classes;
});

Advanced option

For larger PHP changes, use a child theme or a small custom plugin instead of snippets.