badget

Biggest Sale! Special Offer!

Get 30% discount on all of our single themes with this coupon code: #30%SALE

Hurry up! *Limited time offer*

Reply To: Child theme and modified code

#16473
grendizer
Member

Hello again. So I have searched again by studying the functions and by reading articles on the web. I finally managed to do what i wanted. I’m putting here my conclusions to help other people with the same problem:

1) First, I noticed the function cleanretina_featured_post_slider() was OUTSIDE the function cleanretina_headerdetails(). There is a closing “}” before all bottom functions such as cleanretina_featured_post_slider(). As a result, in the child theme’s functions.php, there is NO need to refer to the function cleanretina_headerdetails().

2) Second, there are 2 ways to replace a parent function with a child fonction.
– First solution : Deactivate the Parent Function then Activate the Child Function: http://venutip.com/content/right-way-override-theme-functions . This is what I was trying to do.
– Second solution : use “pluggable” functions : http://codex.wordpress.org/Child_Themes#Using_functions.php : TIP FOR THEME DEVELOPERS. The fact that a child theme’s functions.php is loaded first means that you can make the user functions of your theme pluggable —that is, replaceable by a child theme— by declaring them conditionally. E.g.:
if ( ! function_exists( ‘theme_special_nav’ ) ) {
function theme_special_nav() {
// Do something.
}
}

3) According to the code in header-extension.php, Theme Horse’s developpers are using the second solution for the function I’m interested in. The following line:
if ( ! function_exists( ‘cleanretina_featured_post_slider’ ) ) :
means that if the function cleanretina_featured_post_slider does not exist, then it should be run. But, the child theme’s functions.php is loaded before the parent theme’s functions. So if the same function already exists in the child theme, it will not run in the parent theme!

4) So my code in the child theme’s functions.php is very simple:
<?php // Opening PHP tag – nothing should be before this, not even whitespace
function cleanretina_featured_post_slider() {
//original code pasted here , then modified for my own needs.

5) It’s a lot of work and research for a simple bug, so I repeat: Theme Horse should fix once and for good the conflict between CleanRetina (Free & Pro) and the Polylang plugin.

Thanks
David