Hooks & Filters
Theme-level hooks and filters let a theme's functions.php extend behavior without touching core files. (Plugins have a separate, similarly-shaped hook system — see Plugin Basics and Hooks & the Plugin Lifecycle.)
Hooks
Available hooks
All eight are pre-registered. You can pass a custom name to add_theme_action() — it creates the entry on the fly — but do_theme_action() only fires hooks the core or your theme actually calls.
| Hook | Fires |
|---|---|
before_header / after_header | Around the <header> element |
before_content / after_content | Around the main content area |
before_footer / after_footer | Around the <footer> element |
header_scripts | Inside <head> |
footer_scripts | Before </body> |
add_theme_action(string $hook, callable $function, int $priority = 10): bool
add_theme_action('before_footer', function() {
echo '<div class="newsletter-banner">Subscribe</div>';
});
Lower $priority runs first.
do_theme_action(string $hook, mixed $args = null): void
Executes all callbacks on a hook, in priority order. Called internally by the CMS — rarely needed directly in theme code.
Filters
There are no built-in named filters — any string key works as one.
add_theme_filter(string $hook, callable $function, int $priority = 10): bool
The callback receives the current value and must return a value.
add_theme_filter('footer_text', fn($text) => $text . ' — Powered by SynaptikCMS');
apply_theme_filters(string $hook, mixed $content): mixed
Passes $content through every filter on $hook, in priority order. Returns $content unchanged if none are registered.
$text = apply_theme_filters('footer_text', $settings['footer_text']);
Theme options
In-memory key/value pairs, scoped to the current request — useful for passing data from functions.php to templates without globals.
set_theme_option('show_sidebar', true);
// ...
if (get_theme_option('show_sidebar')) { include 'sidebar.php'; }
get_theme_option(string $name, mixed $default = null): mixed.
Asset helpers
style.css and script.js are already injected automatically by render_header_scripts() — these are for additional assets only.
add_theme_stylesheet(string $stylesheet): void
add_theme_stylesheet('css/custom.css');
add_theme_script(string $script, bool $in_footer = true): void
add_theme_script('js/animations.js');
$in_footer = true → footer_scripts hook; false → header_scripts hook.
Page detection
is_home(): bool and is_current_page(string $type, string $slug = ''): bool — see Utility Functions for usage examples.
