DEV3 Technologies home

DEV3 Developer Forum

Should custom WordPress code go in a child theme or a custom plugin?

WordPress helpSolved0 views

1 reply

dev3 · Accepted answer

Rule of thumb: presentation goes in the theme, functionality goes in a plugin.

Child theme is for

  • CSS changes and template overrides (header.php, single.php, partials copied from the parent).
  • Small display-related hooks such as changing excerpt length, or theme-specific image sizes.
  • Registering widget areas or menu locations used by this theme.

Plugin is for

  • Custom post types and taxonomies, shortcodes, REST routes, business logic, integrations, scheduled tasks, custom blocks.
  • Anything that should survive a change of theme. If a post type lives in functions.php, switching themes makes the content disappear from the admin.

For your list: shortcode and post type go in a small plugin, the CSS tweaks in the child theme (or Additional CSS in the Customizer).

Minimal plugin:

<?php
/**
 * Plugin Name: Client Site Functions
 * Description: Site-specific functionality.
 * Version: 1.0.0
 */
defined( 'ABSPATH' ) || exit;

add_shortcode( 'year', fn() => esc_html( gmdate( 'Y' ) ) );

Save it as wp-content/plugins/client-site-functions/client-site-functions.php and activate it.

Must-use plugins (wp-content/mu-plugins/) load automatically, cannot be deactivated from the admin, and suit essential site rules.

Pitfalls

  • Do not paste random snippets into the parent theme.
  • Prefix function names and handles (client_), and guard with defined( 'ABSPATH' ).
  • With block themes (full site editing), the child theme can carry theme.json overrides; see the DEV3 child theme starter.
0

Your reply

Every post is reviewed by DEV3 before it appears. Usually reviewed within 24 hours.

Markdown supported. Use ``` for code blocks. Images are not allowed.