Replacing parent function in child theme
I’m trying to replace the function
graphene_column_mode()from the file
templates/theme-utils.php(line 111), with a modified function in my child theme
My problem is that
graphene_column_mode()is not under the
function_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
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 the
Cannot redeclare graphene_column_mode()error, and I cannot just change the
header.phpfile (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.phpfor 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
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:
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 conditional
function_exists()and be sure that I’ll have no problems with future updates.
Is that correct?
- You must be logged in to reply to this topic.