TT4 Child Theme – A ton of wonders and stuff not working
-
Hi TT4
I have scraped manual after manual, and I really need some clarification to move further… I have setup a child theme for tt4 that apparently sort of works. Style Css is in place and declaring TT4 as parent. Woo specifies that child theme is theme and TT4 is parent. I declare tt4 to woo using a snippet in child functions.php, so this file also works. Furthermore, I have added theme.json and screenshot.png.
The following is totally unclear for now:
- Front Page – Query of blogs at bottom and footer does not show on my frontpage. Why? They show in editor.
- How du I activate style.css (child) so that additions show on site and also in editor?
- Fonts are not showing correct. Basically I am using Cardo and Inter as default TT4, however, the display is not ported to child correct. Paragraphs show as Cardo font and other strange things are happening that I didn’t ask for. Why is this? and how to overcome?
- Templates, Parts and Patterns. I have copy pasted those from tt4 into child. Yes everything, yet some of my custom work does not show? Also I wonder: If I copy from TT4, will that not overwrite stuff in TT4? In other words, I need to create custom stuff with other title and slug if I want parent theme stuff to show? My concern is if I switch to fx TT5 theme, the new templates from parent will not show in editor if they are identical (Title, Slug) to what is in my child theme? Or have I misunderstood? It’s really important to me, I get this right since I want both parent default (Now and future) and also custom child stuff to show in editor.
- theme.json variables – (I have read the manuals and I do not find my answer). As I understand theme.json child coexists with parent theme.json and takes priority over parent if same stuff is in there with new color etc. Settings displays in editor or does it? Custom styles is other styles than the ones in native tt4. So how do I create simple variables such as color, font-size etc. like this: var(–wp–preset–color–accent-3), and this var(–wp–preset–font-size–medium). I use default styles, I just need custom variables coexisting with default variables……! Where and how do I define them?
- theme.json core stuff – Altering fx core button, I assume I can copy paste from parent theme.json to child theme.json and then alter to my liking, and then this will overwrite parent? Is this correct?
So in short I have structure issues not working and basically I want to create variables next to TT4 default and make them available in settings, but also have those for plugin css to make them adapt at theme change etc.
Thx
The page I need help with: [log in to see the link]
-
Examples of issues I see:
Editor does not show in frontend:
Blog page editor with exerpt and author
Blog Page frontend no exerpt and centered heading
Front Page editor with post query and footer
Front page ends here No blog query and no footer
Editor Product catalogue template with footer
Shop page ends here without footer
Fonts TT4 default style
Paragraphs show serif. Is this Cardo or not? They should be inter.
Are heading Cardo or not?
In editor all fonts are inter
Apparently something is consistently wrong. I really need help so come on someone.
Thx
Child theme json:
{
"$schema": "https://schemas.wp.org/wp/6.6/theme.json",
"version": 3,
"patterns": [],
"settings": {
"color": {
"palette": [
{
"name": "Black",
"slug": "black",
"color": "#000000"
},
{
"name": "White",
"slug": "white",
"color": "#ffffff"
},
{
"name": "Draupnir 8",
"slug": "draupnir-8",
"color": "#171717"
},
{
"name": "Draupnir 9",
"slug": "draupnir-9",
"color": "#ae1100"
}
]
}
}
"styles": {. EDITOR SAYS THERE IS AN ERROR HERE. WHATS THE ERROR?
"blocks": {
"core/button": {
"variations": {
"outline": {
"spacing": {
"padding": {
"bottom": "calc(0.6rem - 1px)",
"left": "calc(1rem - 1px)",
"right": "calc(1rem - 1px)",
"top": "calc(0.6rem - 1px)"
}
},
"border": {
"width": "1px"
}
}
}
},
"core/buttons": {
"spacing": {
"blockGap": "0.7rem"
}
},
"core/search": {
"css": "& .wp-block-search__input{border-radius:.33rem}",
"typography": {
"fontSize": "var(--wp--preset--font-size--small)"
},
"elements": {
"button": {
"border": {
"radius": { "ref": "styles.elements.button.border.radius" }
}
}
}
},
"color": {},
"elements": {
"button": {
":active": {
"color": {
"background": "var(--wp--preset--color--contrast)",
"text": "var(--wp--preset--color--base)"
}
},
":focus": {
"color": {
"background": "var(--wp--preset--color--contrast-2)",
"text": "var(--wp--preset--color--base)"
},
"outline": {
"color": "var(--wp--preset--color--contrast)",
"offset": "2px"
},
"border": {
"color": "var(--wp--preset--color--contrast-2)"
}
},
":hover": {
"color": {
"background": "var(--wp--preset--color--contrast-2)",
"text": "var(--wp--preset--color--base)"
},
"border": {
"color": "var(--wp--preset--color--contrast-2)"
}
},
"border": {
"radius": ".33rem",
"color": "var(--wp--preset--color--contrast)"
},
"color": {
"background": "var(--wp--preset--color--contrast)",
"text": "var(--wp--preset--color--base)"
},
"spacing": {
"padding": {
"bottom": "0.6rem",
"left": "1rem",
"right": "1rem",
"top": "0.6rem"
}
},
"typography": {
"fontSize": "var(--wp--preset--font-size--small)",
"fontStyle": "normal",
"fontWeight": "500"
}
},
},
},
"templateParts": [],
"customTemplates": []
}Ref. above. Theme.json line 35 expects a , as opposed to “. What am I misssing?
I changed the blockgap for buttons block in child theme.json. It takes no effect, and I assume something is really not working. Question again: Can I have a child of schema 3 on a parent of schema 2 such as TT4??????? Should I not declare version in a CHILD THEME?
Where the f*** is everyone!!!!!
-
This reply was modified 4 months, 1 week ago by
hebhansen.
Hi @hebhansen
The support forums are responded to by volunteers. While I entirely understand the frustration that issues like the one you’re experiencing can cause, you are infinitely less likely to inspire a response when you are unkind in the way you ask your question.
Please be guided by the forum’s guidelines and the community code of conduct.
That being said, let’s look at what you seem to be experiencing. I’ve broken this down into clear areas so that you could see the full picture and how things are engaging with the other.
- Theme.json Syntax Error
Your immediate issue is a JSON syntax error. I’ve shown the fix as a comment in the ‘error’ location:
{
"$schema": "https://schemas.wp.org/wp/6.6/theme.json",
"version": 3,
"patterns": [],
"settings": {
"color": {
"palette": [
{
"name": "Black",
"slug": "black",
"color": "#000000"
},
{
"name": "White",
"slug": "white",
"color": "#ffffff"
},
{
"name": "Draupnir 8",
"slug": "draupnir-8",
"color": "#171717"
},
{
"name": "Draupnir 9",
"slug": "draupnir-9",
"color": "#ae1100"
}
]
}
}, // ← Fixing this means adding a comma here
"styles": {
// ... rest of styles
}
}- Child Theme Structure
For the child theme to work properly, ensure that you have this basic file/folder structure:
twenty-twenty-four-child/
├── style.css
├── functions.php
└── theme.jsonStyle.css Requirements
Here’s the minimal style.css needed:/*
Theme Name: Twenty Twenty-Four Child
Template: twentytwentyfour
Version: 1.0
*/functions.php
Check this file to ensure that there is proper theme inheritance from the parent theme. Normally, you are guided to use the correct handle for your parent theme’s stylesheet (and you’d update that accordingly, of course).<?php
function tt4_child_enqueue_styles() {
wp_enqueue_style('tt4-child-style',
get_stylesheet_uri(),
array('twentytwentyfour-style'),
wp_get_theme()->get('Version')
);
}
add_action('wp_enqueue_scripts', 'tt4_child_enqueue_styles');Let’s further break down some of the issues you’re having with the templates and theme.json file
1. Template Parts Not Showing:
- Don’t copy all the template parts from parent theme
- Rather, only create template parts that you want to customize
- Use unique slugs for your custom template parts
2. Font Issues:
Add font settings to your theme.json file:
{
"settings": {
"typography": {
"fontFamilies": [
{
"name": "Inter",
"slug": "inter",
"fontFamily": "\"Inter\", sans-serif"
},
{
"name": "Cardo",
"slug": "cardo",
"fontFamily": "\"Cardo\", serif"
}
]
}
},
"styles": {
"typography": {
"fontFamily": "var(--wp--preset--font-family--inter)"
},
"elements": {
"heading": {
"typography": {
"fontFamily": "var(--wp--preset--font-family--cardo)"
}
}
}
}
}- Custom Variables:
Define custom properties in theme.json:
These can then be used as var(–wp–custom–spacing–small).- Version Compatibility:
- It’s fine to use schema version 3 in the child theme even if the parent uses version 2
- The child theme settings will take precedence over the parent theme
Remember:
- Only override what you need to customize
- Use unique slugs for custom templates and parts
- The child theme’s theme.json will merge with the parent’s, with child taking precedence
I’ll end with some links to ensure that you have a place to reference these while you continue to build.
Child Themes – Theme Handbook provides comprehensive guidance on child theme creation and best practices.
Global Settings and Styles (theme.json) provides comprehensive information on setting global styles, block styles, and editor settings within your theme.Additionally, the Introduction to theme.json offers a walkthrough of setting up your theme.json file, and shares some foundational concepts for configuring your global settings and styles.
Hope this all helps. And remember.. be kind. 🙂
Pardon me @janmtm
After asking in fixing wp, develop wp, tt4 and now tt5 forums for any advice on the FSE mess (Please note I love the fse concept) that for 3-4-5 years has not been sorted, patience is running low. No blame on people, but I don’t get why new themes, patterns and blocks roll out while core is a direct route to disaster. Let me elaborate:
I started my current site as multisite on TT4. Did some edits and all good. I decided I need a child theme for many reasons. Child added. Waiting for little to no help, TT5 roll’ed out. Waiting again for a month, I pointed child to TT5.
Only yesterday I learned that because of the core mess, my site is running off theme in database. So part child and part who knows what? TT5 or TT4 or both and then some child. There’s not really any way of knowing, but guessing. And how is it even possible? A newbie would be left in the dark. As also I was. So to any @developer. Please STOP and fix core basic stuff and installation. Any and all will fall into this pit.
I am now heading into database to point tables to the child theme, and that adds a lot of risk I would say.
That said, this is running old.- Theme.json was fixed a month ago and comma added, but thx.
- Yes provided that you have a virgin install, that did not trigger the database theme yet. Adding a comma in editor before adding the child you are in dire straits. I have the child structure in place. Update child theme documentation on these struggles is a very good idea. Fixing core is an even better one.
- Templates – I learned yesterday that ONLY page allows multiple templates. Of all other only one can exist????? Idea of templates is to have alternatives. Especially on a multisite. Also “Make available on Network” directly in editor > templates would be great as would duplicate template option!
- Template parts – well I did copy all, cause there was no documentation on this. I will need to clean up the mess eventually, since I am now on parent TT5 !?!? But now I know.
- Variables – I am still looking for the doc that lays out all variables available so that they may be used in plugins’ legacy css and temporary css as theme.json evolves.
- Fonts. This was sorted in parent TT4 and now broken in parent TT5, since theme has no idea what theme it is. Same for colors and all other styles.
- Schema – Yep 2 parent works with child 2. TT5 is on schema 3 as is my child, so that should not create inconsistency once theme know what it is.
- unique slugs – Back to core FSE. Reserve the slugs you can possibly think of using. Ex: wp-fse-*. Have the code check if any custom stuff has this slug and then issue warning, force another slug or whatever. Just get it idiot proof. It’s essential.
To whom it may concern. Here are some enqeueus for child functions.php with conditions and dependencies:
/*******************************************************************
********** Enqeueu functions - functions.php includes *************
********* Sub functions may be targeted conditionally *************
******************************************************************/
function draupnir_9_enqueue_plugin_functions() {
// Helper function to send email notification to admin
function send_admin_email_notification($subject, $message) {
// Get the admin email from WordPress settings
$admin_email = get_option( 'admin_email' );
// Set email headers
$headers = array('Content-Type: text/html; charset=UTF-8');
// Send email
wp_mail( $admin_email, $subject, $message, $headers );
}
// Include theme setup functions
require_once get_stylesheet_directory() . '/path-to-functions/theme-setup.php';
// Include custom post types functions
require_once get_stylesheet_directory() . '/path-to-functions/custom-post-types.php';
// Include other custom functions
require_once get_stylesheet_directory() . '/path-to-functions/custom-functions.php';
// Optionally, include admin-specific functionality
if ( current_user_can( 'administrator' ) ) {
require_once get_stylesheet_directory() . '/path-to-functions/admin-functions.php';
}
// Check if WooCommerce is active and include its functions
if ( class_exists( 'WooCommerce' ) ) {
$file_path = get_stylesheet_directory() . '/path-to-functions/woocommerce-functions.php';
if ( file_exists( $file_path ) ) {
require_once $file_path;
} else {
// Log error and notify admin via email
$error_message = 'WooCommerce functions file not found: ' . $file_path;
error_log( $error_message );
// Send email notification
send_admin_email_notification( 'Error: Missing WooCommerce Functions File', $error_message );
}
}
// Check if WCFM Marketplace plugin is active
if ( is_plugin_active( 'wc-multivendor-marketplace/wc-multivendor-marketplace.php' ) ) {
// Include general WCFM functions
$file_path = get_stylesheet_directory() . '/path-to-functions/wcfm-functions.php';
if ( file_exists( $file_path ) ) {
require_once $file_path;
} else {
// Log error and notify admin via email
$error_message = 'WCFM functions file not found: ' . $file_path;
error_log( $error_message );
// Send email notification
send_admin_email_notification( 'Error: Missing WCFM Functions File', $error_message );
}
// Include vendor-specific functions
if ( current_user_can( 'wcfm_vendor' ) ) {
$file_path = get_stylesheet_directory() . '/path-to-functions/wcfm-vendor-functions.php';
if ( file_exists( $file_path ) ) {
require_once $file_path;
} else {
// Log error and notify admin via email
$error_message = 'Vendor WCFM functions file not found: ' . $file_path;
error_log( $error_message );
// Send email notification
send_admin_email_notification( 'Error: Missing Vendor WCFM Functions File', $error_message );
}
}
// Include admin-specific functions
if ( current_user_can( 'administrator' ) ) {
$file_path = get_stylesheet_directory() . '/path-to-functions/wcfm-admin-functions.php';
if ( file_exists( $file_path ) ) {
require_once $file_path;
} else {
// Log error and notify admin via email
$error_message = 'Admin WCFM functions file not found: ' . $file_path;
error_log( $error_message );
// Send email notification
send_admin_email_notification( 'Error: Missing Admin WCFM Functions File', $error_message );
}
}
}
// Check if Amelia Booking is active and include its functions
if ( class_exists( 'Amelia\Classes\Context' ) ) {
$file_path = get_stylesheet_directory() . '/path-to-functions/amelia-functions.php';
if ( file_exists( $file_path ) ) {
require_once $file_path;
} else {
// Log error and notify admin via email
$error_message = 'Amelia functions file not found: ' . $file_path;
error_log( $error_message );
// Send email notification
send_admin_email_notification( 'Error: Missing Amelia Functions File', $error_message );
}
}
// Include enqueue scripts/styles
require_once get_stylesheet_directory() . '/includes/enqeue-scripts.php';
}
add_action( 'after_setup_theme', 'draupnir_9_enqueue_plugin_functions' );For inspiration, here are some css enqeueus for child:
/******************************************************************
********* Enqeuue Stylessheets - style.css and sub css *************
********** Sub styles reside in folder /my-path/ **************
******************************************************************/
function draupnir_9_enqueue_styles() {
// Enqueue the child theme's style.css (No dependencies)
wp_enqueue_style(
'draupnir-9-style',
get_stylesheet_uri(),
array(), // No dependencies here
null, // No version number
'all' // For all media types
);
// Enqueue the child theme's editor style (No dependencies)
wp_enqueue_style(
'draupnir-9-editor-style',
get_stylesheet_uri(), // This will load style.css in the editor as well
array(), // No dependencies here
null,
'all'
);
// Conditionally enqueue WooCommerce styles and product-page.css (only if WooCommerce is active)
if ( class_exists( 'WooCommerce' ) ) {
// Enqueue WooCommerce styles
wp_enqueue_style(
'draupnir-9-woo',
get_stylesheet_directory_uri() . '/my-path/woo.css',
array( 'woocommerce-general' ), // Depends on WooCommerce styles
null,
'all'
);
// Enqueue product-page.css on product pages (only if WooCommerce is active)
if ( is_product() ) {
wp_enqueue_style(
'draupnir-9-product-page',
get_stylesheet_directory_uri() . '/my-path/product-page.css'
);
}
}
// Check if WCFM is active and load styles accordingly
if ( is_plugin_active( 'wc-multivendor-marketplace/wc-multivendor-marketplace.php' ) ) {
// Conditionally enqueue WCFM styles
wp_enqueue_style(
'draupnir-9-wcfm',
get_stylesheet_directory_uri() . '/my-path/wcfm.css',
array(), // No dependency on WCFM core styles here, if it’s not necessary
null,
'all'
);
// Check if user is a WCFM vendor OR an administrator and enqueue vendor styles
if ( current_user_can( 'wcfm_vendor' ) || current_user_can( 'administrator' ) ) {
wp_enqueue_style(
'draupnir-9-wcfm-vendor',
get_stylesheet_directory_uri() . '/my-path/wcfm-vendor.css',
array(), // No dependency on WCFM core styles
null,
'all'
);
}
}
// Conditionally enqueue amelia.css for Amelia Bookings & Events styles (only if Amelia is active)
if ( class_exists( 'Amelia\Classes\Context' ) ) {
wp_enqueue_style(
'draupnir-9-amelia',
get_stylesheet_directory_uri() . '/my-path/amelia.css',
array( 'amelia' ), // Depends on Amelia's core styles
null,
'all'
);
}
// Enqueue global.css for general styles
wp_enqueue_style(
'draupnir-9-global',
get_stylesheet_directory_uri() . '/my-path/global.css',
array(), // No dependencies
null,
'all'
);
// Enqueue forms.css for form styles
wp_enqueue_style(
'draupnir-9-forms',
get_stylesheet_directory_uri() . '/my-path/forms.css',
array(), // No dependencies
null,
'all'
);
}
// Enqueue the child theme's styles after WordPress styles (priority 20)
add_action( 'wp_enqueue_scripts', 'draupnir_9_enqueue_styles', 30 );
// Enqueue the child theme's editor styles after WordPress editor styles (priority 20)
add_action( 'enqueue_block_editor_assets', 'draupnir_9_enqueue_styles', 20 );No worries @hebhansen !
Thank you so much for sharing your process, and tips. This could benefit other persons working with the same steps.
-
This reply was modified 4 months, 1 week ago by
- You must be logged in to reply to this topic.