DigiFlash is built as a block theme, which means it relies primarily on WordPress core hooks and filters rather than custom theme-specific hooks. This approach maintains compatibility with WordPress standards and makes the theme lightweight and fast.
WordPress Core Hooks Used by DigiFlash
DigiFlash uses standard WordPress hooks for its core functionality. Understanding these hooks allows you to extend the theme without modifying core files.
wp_enqueue_scripts
Used to load theme stylesheets and scripts:
add_action('wp_enqueue_scripts', 'digiflash_styles');
You can hook into this to add your own assets:
function my_custom_assets() {
wp_enqueue_style('my-custom-style', get_stylesheet_directory_uri() . '/custom.css');
wp_enqueue_script('my-custom-script', get_stylesheet_directory_uri() . '/custom.js', array(), '1.0', true);
}
add_action('wp_enqueue_scripts', 'my_custom_assets', 20);
The priority 20 ensures your function runs after DigiFlash’s default styles.
after_setup_theme
Used for theme setup and registering editor styles:
add_action('after_setup_theme', 'digiflash_editor_style');
Hook into this for theme setup tasks:
function my_theme_setup() {
// Add custom image sizes
add_image_size('custom-size', 800, 600, true);
// Add theme support features
add_theme_support('post-thumbnails');
add_theme_support('custom-logo');
}
add_action('after_setup_theme', 'my_theme_setup');
init
While not explicitly used in DigiFlash’s core functions.php, the init hook is available for registering patterns, post types, and taxonomies:
function my_custom_init() {
// Register custom block pattern category
if (function_exists('register_block_pattern_category')) {
register_block_pattern_category(
'custom-category',
array('label' => __('Custom Category', 'textdomain'))
);
}
}
add_action('init', 'my_custom_init');
Block-Specific Hooks
Since DigiFlash is a block theme, you can use WordPress block hooks to modify block output:
render_block
Filter individual block output:
function modify_digiflash_blocks($block_content, $block) {
// Modify specific block types
if ($block['blockName'] === 'core/heading') {
// Add custom class to all headings
$block_content = str_replace('<h', '<h class="custom-heading" ', $block_content);
}
return $block_content;
}
add_filter('render_block', 'modify_digiflash_blocks', 10, 2);
render_block_{block_name}
Target specific block types:
function modify_button_block($block_content, $block) {
// Add custom tracking to all buttons
$block_content = str_replace('<a ', '<a data-tracking="button-click" ', $block_content);
return $block_content;
}
add_filter('render_block_core/button', 'modify_button_block', 10, 2);
Template and Pattern Hooks
get_block_templates
Filter available templates:
function add_custom_templates($templates) {
// Add or modify templates programmatically
return $templates;
}
add_filter('get_block_templates', 'add_custom_templates');
default_wp_template_part_areas
Register custom template part areas:
function add_template_part_areas($areas) {
$areas[] = array(
'area' => 'sidebar',
'label' => __('Sidebar', 'textdomain'),
'description' => __('Custom sidebar area', 'textdomain'),
'area_tag' => 'aside',
);
return $areas;
}
add_filter('default_wp_template_part_areas', 'add_template_part_areas');
Content Hooks
Standard WordPress content hooks work with DigiFlash:
the_content
Modify post content output:
function add_content_before($content) {
if (is_single()) {
$custom_content = '<div class="before-content">Custom message</div>';
$content = $custom_content . $content;
}
return $content;
}
add_filter('the_content', 'add_content_before');
wp_head and wp_footer
Add custom code to header or footer:
function add_custom_head_code() {
echo '<meta name="custom" content="value">';
}
add_action('wp_head', 'add_custom_head_code');
function add_custom_footer_code() {
echo '<script>console.log("DigiFlash loaded");</script>';
}
add_action('wp_footer', 'add_custom_footer_code');
Navigation Hooks
wp_nav_menu_args
Modify navigation menu arguments:
function modify_nav_menu_args($args) {
if ($args['theme_location'] === 'primary') {
$args['menu_class'] = 'custom-menu-class';
}
return $args;
}
add_filter('wp_nav_menu_args', 'modify_nav_menu_args');
Admin and Editor Hooks
admin_enqueue_scripts
Add styles or scripts to the block editor:
function enqueue_editor_assets() {
wp_enqueue_style(
'custom-editor-style',
get_stylesheet_directory_uri() . '/editor-custom.css',
array(),
'1.0'
);
}
add_action('admin_enqueue_scripts', 'enqueue_editor_assets');
enqueue_block_editor_assets
Specifically for block editor assets:
function custom_block_editor_assets() {
wp_enqueue_script(
'custom-editor-script',
get_stylesheet_directory_uri() . '/editor.js',
array('wp-blocks', 'wp-element', 'wp-editor'),
'1.0'
);
}
add_action('enqueue_block_editor_assets', 'custom_block_editor_assets');
Body and Post Classes
body_class
Add custom body classes:
function add_digiflash_body_classes($classes) {
if (is_front_page()) {
$classes[] = 'custom-homepage';
}
return $classes;
}
add_filter('body_class', 'add_digiflash_body_classes');
post_class
Add custom post classes:
function add_digiflash_post_classes($classes) {
if (has_post_thumbnail()) {
$classes[] = 'has-featured-image';
}
return $classes;
}
add_filter('post_class', 'add_digiflash_post_classes');
Removing or Modifying Parent Theme Hooks
To remove a parent theme hook in a child theme:
function remove_parent_hook() {
remove_action('wp_enqueue_scripts', 'digiflash_styles');
}
add_action('after_setup_theme', 'remove_parent_hook');
Then add your own version with a different function name.
Priority and Execution Order
All hooks accept a priority parameter (default is 10). Lower numbers execute earlier:
// Executes early
add_action('wp_head', 'my_function', 5);
// Executes at default time
add_action('wp_head', 'my_function', 10);
// Executes late
add_action('wp_head', 'my_function', 99);
Use priorities to control when your code runs relative to DigiFlash’s default functions.