Unable to create a Wordpress child theme - php

So I'm trying to create a child theme called premierpas from the wordpress theme "fullscreen-agency". I create the premierpas folder in the themes, then I added a css file with that content :
/*
Theme Name: Premier Pas
Author: Garga Le Noir
Template: fullscreen-agency
Version: 1.0.0
*/
and a functions.php with this content :
<?php
function premierpas_enqueue_styles() {
$parent_style = 'fullscreen-agency';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),null);
}
I've tried quite a few other versions of the functions code, without success.
When I try to activate it, my website just breaks. I only have a message telling me there is a technical problem, and I get an email to activate the recovery mode.
I'm sure the error is trivial and I'm sorry if I'm wasting your time, but I'm quite stuck on this... Any help will be appreciated, thanks in advance

I created a child theme with the code you stated above and it worked for me. The one change I made was I set the parent to be twentyfifteen since I didn't have your fullscreen-agency parent theme. I assumed your file paths were...
wp-content/themes/premierpas/style.css
wp-content/themes/premierpas/functions.php
A couple things to try...
Remove your functions.php file. If that solves the issue then perhaps you already have premierpas_enqueue_styles() defined in your parent theme or there is some related error.
Enable the debug.log by adding the following to your wp-config.php file... define( 'WP_DEBUG', true ); then try reactivating the child theme and look at your wp-content/debug.log file to see if there are any relevant errors thrown that can help you troubleshoot further.

Related

Cannot get wordpress child-theme css to load/enqueue after plugins

I used a plugin to auto-generate a child theme and necessary files, and it did a good job...my new style.css loads after the parent and works great. the problem is that I have a plugin that requires heavy modification to it's injected divs, and it is a nightmare to overwrite anything because they !important the entire sheet, so I have to work around it.
I'm trying to enqueue my child-theme style.css after the plugin using a priority 99 thing I found on another thread here, and it isn't doing anything. All I did was append to the end of my child functions.php.
Potential issue 1: I did not remove the previous code to enquee this css file...do I need to do that? I thought maybe it would just re-enqueue it if it got to this new code at the end of the file. But maybe it does it once and ignores my code since it's already done.
Potential issue 2: Code error on my part. If my style.css is in the same folder as my functions.php I refer to the file as just 'style.css' right? I assume so because of relative locations because I was not sure if PHP required something that I am unaware of.
Here is my code that is not working.
wp_enqueue_style( 'child-css', get_template_directory_uri() . 'style.css' );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles', 99 );
I also saw this in my functions.php...it's weird because it looks like it's trying to enqueue a parent theme css file, but the relative location points to the child theme. Very confusing. it already had the same add_action priority thing in it from the thing I posted above, so I just change the number to 99, but it also didn't work. It was set to 10.
add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );
if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
function chld_thm_cfg_parent_css() {
wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array( 'font-awesome-5-free','saasland-dark-support','bootstrap','themify-icon','saasland-elementor','saasland-remove-animation','magnific-popup','eleganticons','saasland-wpd','saasland-main','saasland-elements','saasland-comments','saasland-footer','saasland-gutenberg' ) );
}
endif;
add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 99 );
Any tips? Thanks
get_template_directory_uri will always refer to the parent theme folder for assets.
get_stylesheet_directory_uri will refer to the "current" theme folder for assets (which could be the parent or the child, depending on where it is called).
If you are enqueueing style.css file for the child theme then,
wp_enqueue_style( 'child-css', get_stylesheet_directory_uri() . '/style.css' );

Cached version of child theme css loading after updated css file?

I'm building a wp child theme of ThemeGrill's ColorMag. When I load the page, my child theme css file is loaded, but there is also a file called style.css?ver=5.3.2 loaded after it. When I look at the code under elements in the dev tools, it appears to be a cached version of my style.css file.
I've deleted the child theme folder and reuploaded all of my files but I see the same result. I also have wp-cache level set to 0
Also I should note, I'm new to wp and couldn't figure out how to enqueue the child theme properly, so style.css is loaded via an href in my header.php. my functions.php looks like this:
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
Again, I'm new so any best practices you have would be much appreciated!
Site is here.

Wordpress child theme style.css has stopped working

really hoping someone can please help me! I just updated the Divi parent theme on my Wordpress site (www.ellymacdonalddesign.com), and the child CSS theme seems to have stopped working.
I've tried the solutions from this question, but they do not seem to work for me:
Wordpress child theme style.css not working
My child functions.php file is currently:
<?php
function my_theme_enqueue_styles() {
$parent_style = 'divi-style';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( $child-style, get_stylesheet_uri() );
}
?>
Would really appreciate any guidance please, thank you in advance,
Elly
Is your variable $child-style have any value? According to document, the handle name (first parameter) is required. That's why your child theme still not working.
Try below code to see if it's work:
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
$parent_style = 'divi-style';
$child_style = 'divi-style-child';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( $child_style, get_stylesheet_uri() );
}
Changing the css child theme version number helped solve the problem on my website.
My child theme was working correctly until I decided to change some css rules in the style.css file from the Wordpress 'Theme Editor' interface. I remarked that no changes appeared on the website, although the css was obviously loaded in the header and also I purged all cache.
I tried solutions of the following question but I think this is for new child theme installation, not an already working one: Wordpress child theme style.css not working
I decided to change the version number of my child theme, and the modifications were finally taken into account.
/*
Theme Name: Chromatic-child
Template: chromatic
Version: 1.1.0
*/

Wordpress Child Theme Needs to pull Multiple style sheets form Parent

I am putting together a wordpress child theme based on a parent theme that has multiple style sheets in it's directory. So for example this is the navigation to a few of the style sheets:
parent-theme/style.css
parent-theme/css/style.css
parent-theme/css/bootstrap.css
I created my child folder and created my style.css file as well as my function.php file but it seems that the child theme is only pulling the style sheet for the parent-theme/style.css file and not pulling all the .css files.
After doing some digging this is where my functions.php file is at currently:
<?php
/* v1.0.5
Date: 5/15/17
*/
function my_theme_enqueue_styles() {
$parent_style = 'wizard-style'; // This is 'wizard' for the Wizard theme.
wp_enqueue_style( $parent_style, get_template_directory_uri() . 'style.css' );
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/css/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>
My main objective is to have the child theme pull all needed stylesheets and utilize the one single style sheet under my child them folder (child-theme/style.css) for any changes I would like to make.
My questions are:
Is this possible?
If it is possible, what errors may be occurring that is causing my fucntion.php file not to pull all the stylesheets?
If it is not possible, what changes do I need to make to my function.php file and my directory to make this work?
I had an issue like this with ArileWP theme, after a lot of research I figured out that loading multiple style sheets was not the issue (using the enqueue function on wordpress.org forums and other forums did in fact load all stylesheets regardless of whether they were in the root level or lower directory levels of the parent theme).
The issue in my case ended up being that Arile requires you to install their "arile extra" plugin, and this plugin has an if statement that is conditional on what your child theme is named:
if( 'ArileWP' == $activate_theme || 'Business Street' == $activate_theme || 'StrangerWP' == $activate_theme || 'NewYork City' == $activate_theme || 'InteriorPress' == $activate_theme || 'Arile WP Child' == $activate_theme ){
require("inc/arilewp/arilewp.php");
Their plugin has a default name Arile WP Child that, if you are not using as the name of your child theme, the extra features included in the plugin will not execute.
The cleanest solution in my case was to simply change the name of my child theme to the one defaulted in their php file.
Might not be the same issue you are having but was a simple fix that just took me a long time to narrow down.
Check the page 'view source' to make sure the style sheets are being loaded from the parent. When you activate a child theme its still pulling everything from the parent unless you override the specific file (example: header.php).
The functions.php and style.css files are the only exception as they supplement their corresponding parent theme file.
So, in summary those stylesheets should be included on your websites. Your theme settings may be incorrect but if you're in a pinch and just need to get those style sheets loaded just add them manually via the functions.php file by
enqueuing them
EDIT:
Does the child theme stylesheet contain the following commented out information customized for your theme, of course?
/*
Theme Name: Twenty Fifteen Child
Theme URI: URI
Description: Twenty Fifteen Child Theme
Author: John Doe
Template: twentyfifteen
Version: 1.0.0
Text Domain: twenty-fifteen-child
*/
If it isn't overriding the parent the styles it could possibly be a cache issue. If you don't have any cache plugins it could be your hosting environment or Cloudflare. If you can clear the server cache then refresh your browser with a Cntrl+F5 and see if that helps.
Did you try adding !important to your child styles for troubleshooting purposes already? Does your theme have a custom style option that lets to save styles to the database that it loads with each page to override the parent theme? Its not ideal but works if youre in a pinch.
Sorry if I am telling you elementary things I am not sure what your experience level is.

Wordpress Child theme for html5blank

I'm having so much trouble setting up a child theme of the html5blank theme. To the point where I'm doing a fresh install of the parent theme and starting from scratch - and writing this post as I go through it! Basically upon creating the child them I now need to load my custom /css/main.css file - and it's not having it! Description of setup process follows:
I've dropped a freshly downloaded html5blank folder into /themes/ and activated it. After that I have created another folder within /themes/ called "html5blank-child". Within that I've created a new, blank style.css and functions.php.
Within style.css I have the following:
/*
Theme Name: HTML5 Blank Child
Theme URI: http://example.com/twenty-fifteen-child/
Description: HTML5 Blank Child Theme
Author: My Name
Author URI: http://myportfolio.com
Template: html5blank
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Text Domain: html5blank-child
*/
And within functions.php I have:
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
?>
With all that done, I active my child theme. With all that done, everything still appears to be working. As I've created static templates of the website, I drop my 'img', 'css', 'font' and 'js' folders into the html5blank-child.
Now my 'actual' CSS file has a path of: html5blank-child/css/main.css
I need to load this file in. I was told to adjust my functions.php CSS path to: /css/main.css ...but it won't load the file at all. I've also tried using get_stylesheet_directory_uri() instead of get_template_directory_uri() as was advised by someone else but no luck!
The reason I've documented the process like this is, last time I got to this point if I went to access the Wordpress admin using http://localhost:8888/websitename/admin it won't redirect to wp-admin like it normally does. Also when I went to save a post, I've get a blank page. Thankfully that isn't happening this time so I guess it's a good (better) start but now I need to get my files loaded in.
Hope someone can help! :)
You need to import the style.css from main theme first inside the style.css of the child theme.
Use #import to import the css file first.
Also remove the parent-style from functions.php of child theme and then include your html5blank-child/css/main.css like the following given,
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
wp_enqueue_style( 'child-main', get_stylesheet_directory_uri() . '/css/main.css' );
}
Load the parent themes style.css first, then load your child themes CSS like this:
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-main', get_stylesheet_directory_uri() . '/css/main.css', array('parent-style') );
}

Categories