overwrite a function in parent theme wordpress - 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

Related

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.

WordPress, using child theme, how can I edit a function

I am using style.css to "add" styles to theme- so it won't get overwrite when i update the theme.
How can i accomplish the same effect with functions?
Suppose i have a function (in the parent theme),
function interio_gmap_shortcode($atts) {
....
....
$str .= '
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false**&language=iw**"></script>
This is what i want to add- &language=iw , it's not exist in the parent theme.
this function exist in shortcodes.php
How can I accomplish that?
If you're properly creating a child theme, you should have your own folder with a styles.css and a functions.php in it.
To override a function like you're describing, you'll need to copy the php function from its original location (either your parent theme's functions.php or shortcodes.php) then make the changes you need in your child theme's functions.php.
It depends on whether the parent theme was coded to allow the function to be overridden. If so, it will probably look something like:
if (!function_exists('interio_gmap_shortcode')) {
function interio_gmap_shortcode($atts) {
...
In this case, you can copy the function to your own functions.php file and change it. At the time that the parent functions.php runs, your function will already exist and will be the one used.
If the parent function.php is not coded something like this, then copying the function to your function.php will result in a "Duplicate Function" error.
In that case, you would need to create your own function with a different name and use that instead.

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

What makes a Wordpress theme an "invalid parent theme"?

In order to overwrite some CSS of an existing Wordpress theme, I would like to create a child theme of it as described on http://codex.wordpress.org/Child_Themes#Example_of_a_basic_Child_Theme .
I created a directory along with the style.css file, where the parent theme's name is defined as "template". So far, so good. When I go to the themes page in Wordpress' administration, I get the message "The [name of parent theme] theme is not a valid parent theme.", and I cannot activate it.
I am wondering how Wordpress finds out if a parent theme is valid or not and if there is a way to make the parent theme a valid parent theme.
In order to find out if the defined parent theme is the problem, I replaced the "template" definition with another theme, which is also installed on the same server, and that worked.
Thanks in advance for your help.
It seems I forgot to mention the fact that caused the problem: My parent theme is already a child theme, and I was not aware of the two generation limit, which means that a child child theme is not possible. :-(
Thanks for your help anyway! Maybe this information should be added on http://codex.wordpress.org/Child_Themes ...
try checking your child theme's css and look at the #import line and make sure there is a ';' semicolon at the end. :)
Your child theme needs to use exactly the same name (same cases, same spaces etc.) as the parent theme. It's defined as Theme Name in the parent's style.css.

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