Replacing parent function in child theme
-
I’m trying to replace the function
graphene_column_mode()
from the filetemplates/theme-utils.php
(line 111), with a modified function in my child themefunctions.php
.My problem is that
graphene_column_mode()
is not under thefunction_exists()
conditional in parent theme, and I didn’t find a way to ‘deactivate’ or override it.Is there a way to accomplish my goal without modify the parent theme?
Otherwise I could add the conditional in parent theme and ask you to add the same in future upgrades of your theme, is that possible?
Thank you for your help and for your great job on graphene theme!
Mod
I don’t have an answer for you (sorry!) but your question intrigues me.
I’m wondering if you want to replace this function to include other templates? If so, how are you going to handle the width issue? If not, what are you going to replace this function with?
My understanding is that the functions in this file are back-end features (i.e., readers to your blog will never interact with them), so my curiosity is piqued. We don’t see a lot of back-end modification here.
Mod
Thinking about it now, this function wouldn’t be under the
function_exists()
conditional, since it is available more or less all the time. Have you tried just adding a replacement function to your functions.php file?Kenneth, about your first question, I don’t need to include other templates. I just want to have a 3 columns layout in home page, and a 2 columns layout in single posts and maybe somewhere else (I’m still working on the design).
I know that this function is available all time, that’s the problem for me to override and replace it. Without the
function_exists()
conditional I get theCannot redeclare graphene_column_mode()
error, and I cannot just change theheader.php
file (where the function is called) in my child theme (to use a child function with a different name), because that function is (about) 4 steps later in the code, after a chain of 3 functions before it.I’ve already added the conditional in
teme-utils.php
for testing my mod, and everything works exactly like i want after that.After all it’s just a line of code to add, and there is a wordpress tip for developers that asks to add the conditional to every function, to make them pluggable.
Mod
I just want to have a 3 columns layout in home page, and a 2 columns layout in single posts and maybe somewhere else
Strange. This can be achieved without hacking theme files, no?
That would be great but I didn’t find a similar option in the back-end.
I’m aware of the possibility to choose the layout on a page basis, but that is not enough for my purpose. I need it to be the default behavior for pages.
Furthermore for single posts that option is not available at all to my eyes.
Am I missing something?
Admin
I missed this thread and Graphene 1.7 has already been submitted to the repository. The function will be pluggable in version 1.7.1.
In the mean time, you can do something like this to achieve different column modes for different posts/pages:
function graphene_modify_column_mode(){
global $graphene_settings;
if ( is_single( 88 ) )
$graphene_settings['column_mode'] = 'two_col_left';
}
add_action( 'template_redirect', 'graphene_modify_column_mode' );Thank you very much Syahir!
I’ll try your code.
Anyway, if the funtion will be pluggable in 1.7.1, I can also just hack the current version of
graphene_column_mode()
with the conditionalfunction_exists()
and be sure that I’ll have no problems with future updates.Is that correct?
Admin
1.7.1 will come after 1.7, so you will need to make the changes again when you update to 1.7.
Viewing 10 posts - 1 through 10 (of 20 total)
- 1
- 2
- You must be logged in to reply to this topic.