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

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.

Related

Add all .css to child themes at one time, or right way to do it one by one?

How to use functions.php to add all the .css to child themes at one time?
If it is not possible at once, how is right way to do it one by one?
Theme: Generatepress
https://sk.wordpress.org/themes/generatepress/
Child: Hand made by Codex
https://codex.wordpress.org/Child_Themes
Adding one CSS file isn't recommended, it's better if you register each new custom CSS individually.
Keep in mind, a child theme will automatically inherit all of the parent's CSS. You should only register CSS files you custom wrote.
This is an example function of loading a CSS file located in the CSS directory within the child theme. It loads a custom file 'CustomFooter.css' on a page with an ID of 45.
add_action( 'template_redirect', 'footer_css' );
function footer_css() {
if (is_page(45)) {
wp_enqueue_style('CustomFooter-style',
get_stylesheet_directory_uri() .
'/CSS/CustomFooter.css?v=1.1', array( 'parent-style'));
}
}

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

overwrite a function in parent theme wordpress

I have a function on parent theme called function ce_seller_bar( $seller )
I want to overwrite it in child theme without deleting it from parent
When I delete it in parent theme it works, when I don't delete it the browser output is:
Fatal error: Cannot redeclare ce_seller_bar()
(previously declared in
C:\wamp\www\CampusAdsList2\wp-content\themes\classifiedengine-child
\includes\template.php:12)
That means that child function had been loaded before parent one
so I want to write the function in child theme so after update I dont lose it
ty
thanks for replay
I took a nap when I woke up,I figured out an easy solution
my solution is to overwirte file /template/ad_detail.php that calls this function and this file doesnt contain functions like template.php so I copy and past it in child theme directory
as I created my new function with defferent name in fuctions.php in child theme as well as I call it new file in /template/ad_detail.php inside child theme and it works fine for me

Overwriting parent's theme files in 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

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