Overwriting parent's theme files in Wordpress - wordpress

It seems like my Wordpress child theme in some cases refuses to use child files and still uses parent's files.
For example I want to override the themex.lesson that is located in the
child_theme/framework/classes/themex.lesson.php folder
Parent's file is in the:
parent/framework/classes/themex.lesson.php folder
Changes that I make to the child_theme themex.lesson php are not reflected in live site. Other changes made to the child theme work perfectly fine.
What could be causing this behavior?

Referencing / Including Files in Your Child Theme
When you need to include files that reside within your child theme's
directory structure, you will use get_stylesheet_directory(). Because
the parent template's style.css is replaced by your child theme's
style.css, and your style.css resides in the root of your child
theme's subdirectory, get_stylesheet_directory() points to your child
theme's directory (not the parent theme's directory).
Here's an example, using require_once, that shows how you can use
get_stylesheet_directory when referencing a file stored within your
child theme's directory structure.\
require_once( get_stylesheet_directory() . '/my_included_file.php' );
Source: https://codex.wordpress.org/Child_Themes

Related

Child themes of twentysixteen theme

I am using twenty sixteen child theme. I need to modify the theme contents. What are the files I need to modify and how? Can anyone explain it in detail.
Advance thanks.
when i use child theme like this i get black screen
This is my site http://i.stack.imgur.com/snSX9.png How to extent the full width of my site..
Read the following documentation about the child themes
Child theme inherits all the functionality and styling of it's parent theme. If you are using child theme and a theme update is applied your changes won't be lost or overwitten
You can quickly create child theme for any theme, just follow the steps given below:
1 Create a folder and name it exactly your theme name; append -child in the name. e.g. creating child theme for twentysixteen theme would be called twentysixteen-child this folder should sit beside parent theme under wp-content/themes/
2- Your child theme should have three files.
style.css
functions.php
screenshot.png
3- In functions.php file you can override parent theme functions.
4 In style.css file you can override parent theme CSS code.
5 If you want to change header design then you have to override header.php file. For this copy header.php file of your parent theme and paste it inside your child theme folder. Now, you can modify the child theme header file as per your requirements.
6 Similarly, you can also override footer.php file in your child theme.
For more info have a look over below thread-
https://codex.wordpress.org/Child_Themes
You need to create at-least one child-theme directory and two main files (style.css & functions.php) under child theme directory. I have given example using Twenty-Thirteen WordPress theme. Step by step explanation is given

How would you replace every instance of get_stylesheet_uri() with get_template_directory_uri()

I am writing a wordpress child theme and I am looking replace every instance of get_stylesheet_uri() with get_template_directory_uri().
This is because the parent theme has declared all enqueues, image paths etc with get_stylesheet_uri and this means that the child theme looks in the child theme for these files. The point of a parent is so that is can be updated easily without risk to the customisations in the child. Short of copying the files (images, styles, scripts) manually to the child each update, I would like to write a function to ensure the correct path to the parent theme is used.
Currently, I am blocking parent styles by dequeueing them, then adding then enqueueing them again with the correct template function (https://wordpress.stackexchange.com/questions/65523/how-do-i-dequeue-a-parent-themes-css-file)
but this does not work for images paths.

Require another file before require file functions.php Wordpress

Same as title, i want require file 'foo.php' before wordpress require 'functions.php' in theme. What's solution? Somebody can help me?
Use a Child Theme.
Basically you just do this:
Create a directory in your themes directory to hold the child theme.
The theme directory is wp-content/themes. You should name the
directory without any space as part of the name, and it is common
practice to use the name of the parent theme folder with “-child”
appended to it. For example, if you are making a child of the
twentyfourteen theme, your folder name would be twentyfourteen-child.
Inside, you can create a functions.php and add the code you want, you can even call other files, like your foo.php:
(...) the functions.php of a child theme does not override its counterpart
from the parent. Instead, it is loaded in addition to the parent’s
functions.php. (Specifically, it is loaded right before the parent’s
file.)
You can also create a plugin, they are loaded before functions.php, you can take a look at the loading order here: https://wordpress.stackexchange.com/questions/26537/between-functions-php-widgets-and-plugins-which-is-loaded-first

Wordpress Mezzanine Flat Theme - shortcode.php in ChildTheme

It seems that an edited copy of shortcodes.php in child-theme of mezzanine flat theme is not working (does not override the parent theme)
I tried copying the whole lib folder where shortcodes.php is located but still not working. Is there anything I need to do to make it work? Other common pages of wordpress (i.e. header and page) override smoothly on child pages.
Thanks in advance.
You can't override shortcodes.php because the child theme replace only template files
But you can create a new file, like custom_shortcodes.php with your custom shortcode, save in your child theme and then include it in functions.php ( include 'custom_shortcodes.php'; )

Wordpress, Gantry Framework, Child Theme?

Does anyone have experience with Gantry Framework?
I am wondering if it is possible to create a child theme based off of the default? Where would I put my css file and can I build off of the current css instead of starting from scratch while still separating my css from the default theme?
Apart from the usual process of creating a WordPress child theme (create a directory, with proper style.css and functions.php), Gantry requires a specific procedure.
You'll need to copy two files from the parent directory to the child theme directory, keeping the structure:
/gantry/theme.yaml
and
/includes/theme.php
Then, edit the copied theme.yaml: the parent must be your parent theme directory name.
On the theme.php, select all text and replace with this:
// Initialize theme stream.
$gantry['platform']->set(
'streams.gantry-theme.prefixes',
array('' => array(
"gantry-themes://{$gantry['theme.name']}/custom",
"gantry-themes://{$gantry['theme.name']}",
"gantry-themes://{$gantry['theme.name']}/common",
"gantry-themes://{$gantry['theme.parent']}",
"gantry-themes://{$gantry['theme.parent']}/common"
))
);
As for css, you must create this file, within your child theme directory:
/custom/scss/custom.scss
It can be formatted in either SCSS or CSS, and will override the theme's core style sheet files.
Creating a Child Theme is very easy.
All you need to do is create a directory in your theme directory, and name it something like "Gantry-child". Inside that folder, add a file called "style.css". Once this is done, you just need to add the Theme Information that tells Wordpress the Child Theme's Name, Author, and Parent Theme.
Inside the new style.css, add:
/*
Theme Name: Gantry Child
Template: rt_gantry_wp
*/
The most important part that lets Wordpress know that this is a child of the Gantry Theme is the "Template" section. This is the name of the PARENT directory in your Themes folder.
What this will do is create a new theme that inherits all of the parent theme's functions. If you also want to inherit the existing parent theme stylesheet, add to style.css:
#import url("../rt_gantry_wp/style.css");
Hopefully this should get you started. Once that's done, you can add your own header, footer, index, functions, or anything else you can think of to extend the parent theme's functionality.
Hopefully this helps get you started.

Resources