Hooks and Filters

Hooks & Filters

Hooks and filters let you extend the CMS without modifying core files.


Hooks

Available hooks

All hooks are pre-registered. You can also pass custom hook names to add_theme_action() — the function creates the entry on the fly — but do_theme_action() will only fire it if your theme or the core explicitly calls it.

HookFires
before_headerBefore the <header> element
after_headerAfter the <header> element
before_contentBefore the main content area
after_contentAfter the main content area
before_footerBefore the <footer> element
after_footerAfter the <footer> element
header_scriptsInside <head>, for <link> and <script> tags
footer_scriptsBefore </body>, for deferred scripts

add_theme_action(string $hook, callable $function, int $priority = 10): bool

Registers a callback on a named hook. Lower priority number runs first.

add_theme_action('before_footer', function() {
    echo '<div class="newsletter-banner">Subscribe</div>';
});

do_theme_action(string $hook, mixed $args = null): void

Executes all callbacks registered on a hook in priority order. $args is passed as-is to each callback. Called internally by the CMS — rarely needed directly in theme code.

// Receiving $args in a callback
add_theme_action('after_content', function($args) {
    // $args is whatever was passed to do_theme_action()
});

Filters

There are no built-in named filters — all filters are custom. Any string key can be used as a filter hook.

add_theme_filter(string $hook, callable $function, int $priority = 10): bool

Registers a filter callback. The callback receives the current value and must return a value.

add_theme_filter('footer_text', function($text) {
    return $text . ' — Powered by SynaptikCMS';
});

apply_theme_filters(string $hook, mixed $content): mixed

Passes $content through all registered filters on $hook in priority order. Returns $content unchanged if no filters are registered.

$text = apply_theme_filters('footer_text', $settings['footer_text']);

Theme options

Key-value pairs stored in memory for the current request only. Useful for passing data from functions.php to templates without globals.

set_theme_option(string $name, mixed $value): void

set_theme_option('show_sidebar', true);
set_theme_option('hero_height', '80vh');

get_theme_option(string $name, mixed $default = null): mixed

if (get_theme_option('show_sidebar')) {
    include 'sidebar.php';
}

Asset helpers

These enqueue additional scripts and stylesheets from the active theme folder. Note that style.css and script.js are already injected automatically by render_header_scripts() — these helpers are for additional assets only.

add_theme_stylesheet(string $stylesheet): void

add_theme_stylesheet('css/custom.css');
// → <link rel="stylesheet" href="{base}theme/my-theme/css/custom.css">

add_theme_script(string $script, bool $in_footer = true): void

add_theme_script('js/animations.js');
// → <script src="{base}theme/my-theme/js/animations.js"></script>

$in_footer = truefooter_scripts hook. $in_footer = falseheader_scripts hook.


Page detection

is_home(): bool

Returns true if the current page is the homepage.

is_current_page(string $type, string $slug = ''): bool

if (is_home()) {
    echo '<div class="hero">…</div>';
}

if (is_current_page('article', 'my-article')) {
    // Article-specific logic
}

Pagination

get_pagination(int $total_items, int $items_per_page, int $current_page, string $type): string

Generates HTML pagination links for a content list. Returns an empty string if there is only one page.

echo get_pagination(count($articles), $settings['articles_per_page'], $currentPage, 'article');