Child Themes
When custom CSS isn't enough — for template overrides, custom functions, and hooks — use a child theme. Setup takes about three minutes.
When you need a child theme
For most customization, the Customizer's Additional CSS is enough. You need a child theme when you want to:
- Override a template file (e.g. change the structure of
single.php). - Add custom PHP functions that should survive theme updates.
- Add custom shortcodes or hooks tied to your design.
- Override a Pro plugin layout (see Custom Layouts).
Create the child theme
Create a folder at wp-content/themes/food-recipes-child/ and add two files:
style.css
/*
Theme Name: Food Recipes Child
Template: food-recipes
Version: 1.0
Description: Child theme for Food Recipes.
*/functions.php
<?php
add_action( 'wp_enqueue_scripts', 'foodrecipes_child_enqueue', 20 );
function foodrecipes_child_enqueue() {
wp_enqueue_style(
'foodrecipes-child',
get_stylesheet_directory_uri() . '/style.css',
array( 'foodrecipes_default' ),
'1.0'
);
}Activate via Appearance → Themes. Your customizations now live in the child theme; the parent (Food Recipes) keeps receiving updates without touching your overrides.
Overriding a template
To override a template file, copy it from the parent theme into the child theme, keeping the same path. WordPress will use the child copy automatically.
Example: to change the homepage layout, copy wp-content/themes/food-recipes/index.php into wp-content/themes/food-recipes-child/index.php and edit. The parent's version is now ignored — your child's runs.
Overriding a Pro layout
The Pro plugin's layouts live at wp-content/plugins/food-recipes-pro/layouts/{layout}.php. To override one:
- Copy the file into your child theme root:
food-recipes-child/{layout}.php. - The plugin's
FRPro_Layouts::override_template()filter checks the child theme first.
Hooks for child themes
The theme exposes a few action hooks for child themes to extend without copying full templates:
foodrecipes_before_header/foodrecipes_after_headerfoodrecipes_before_main/foodrecipes_after_mainfoodrecipes_before_footer/foodrecipes_after_footerfoodrecipes_card_meta— inside each homepage card, for adding metadata.
Example use:
add_action( 'foodrecipes_card_meta', function () {
if ( has_term( '', 'category' ) ) {
echo '<span class="card-cat">' . esc_html( get_the_category()[0]->name ) . '</span>';
}
} );