ThemeShaper Forums » Thematic

Customize functions in child themes

(11 posts)
  • Started 9 years ago by drd76
  • Latest reply from eddiej
  • This topic is resolved
  1. drd76
    Member

    Hi,

    after seeing this magnificent theme framework for the first time I decided to give it a shot and installed it. After activating thematic and a child theme I would now like to customize the theme through the child theme.
    What I wanted to do first was add categories to the header-navigation, so I copied the function which puts together the corresponding output, 'thematic access ()', from the hooks-filters.php to my child-theme functions.php and modified it to display categories.

    Now I get a 'Fatal error: Cannot redeclare thematic_access() (previously declared in /.../wp-content/themes/diemeldung/functions.php:26) in /.../wp-content/themes/thematic/library/extensions/hooks-filters.php on line 64'.

    So this does not seem to work - but how else could I modify what is displayed in the upper navbar?

    The modification works when I put the changes directly into hooks-filters.php but that would kinda defeat the purpose of having a child theme I guess...

    Any help or pointers appreciated,
    Pete

    Posted 9 years ago #
  2. Hey Pete,

    if you want to change thematic_access() you have to remove it first, because it is an action loaded into an action hook.

    Here's how to remove it:

    function new_header() {
        remove_action('thematic_header','thematic_access',9);
    }
    add_action('init', 'new_header');

    You already created something new and here's how to get it back:

    function new_access() {
        <!-- your code here -->
    }
    add_action('thematic_header','new_access',9);

    Hope this helps.

    Cheers,

    Chris

    Posted 9 years ago #
  3. drd76
    Member

    Wow,
    that is exactly what I need - thanks alot, I will be happily testing on, now that I can get my child theme underway...

    njoy the weekend,
    Pete

    Posted 9 years ago #
  4. Hi Chris, I'm having a similar issue. Where do you put the code that removes the old action and adds the new one? I presume it goes somewhere in the child theme directory but no too sure where...

    Posted 9 years ago #
  5. Hey .. the code goes into the child theme's functions.php.

    Cheers,

    Chris

    Posted 9 years ago #
  6. Thanks, I should have known! In the case of the function I want to override (thematic_postfooter), it doesn't appear to be loaded into an action hook. To override the thematic_postfooter in my child theme's functions.php, I've simply declared a new function "my_postfooter" and added the following line below it:
    add_filter('thematic_postfooter', 'my_postfooter').

    Is this the right way to go about it?
    Cheers for your help,
    Eddie

    Posted 9 years ago #
  7. That's perfect! .. Keep in mind that you have to return a $whatever!

    Cheers,

    Chris

    Posted 9 years ago #
  8. Great. Thanks again for the feedback.
    Eddie

    Posted 9 years ago #
  9. This is an interesting problem, its related to the above (overwriting functions).

    I tried to overwrite the thematic function thematic_add_menuclass.Here's the original:

    // Add ID and CLASS attributes to the first ul occurence in wp_page_menu
    function thematic_add_menuclass($ulclass) {
    return preg_replace('/< ul >/', '<ul id="nav" class="sf-menu">', $ulclass, 1);
    }
    add_filter('wp_page_menu','thematic_add_menuclass');

    To overwrite it, I did the following in my child theme's functions.php file:

    function my_add_menuclass($ulclass) {
    return preg_replace('/< ul >/', '<ul id="fubar" class="sf-menu">', $ulclass, 1);
    }
    remove_filter('wp_page_menu','thematic_add_menuclass');
    add_filter('wp_page_menu','my_add_menuclass');
    }

    All my replacement function should do is add the same additional attributes to the first ul as the original function, but to add 'fubar' instead of 'nav'.

    The page menu to be outputted is 2 levels deep, i.e. there is a ul with the primary page links, and a nested ul with one secondary page, something like:

    <div class="menu">
      < ul >
        < li > < a.. > About < /li >
        < li > Disciplines
          < ul >
            < li > < a.. > Judo < /li >
          < /ul >
        < /li >
      < /ul >
    < /div >

    Leaving things as they are (i.e. using the original function), I get this output:

    <div class="menu">
      < ul id="nav" class="sf-menu">
        < li > < a.. > About < /li >
        < li > Disciplines
          < ul >
            < li > < a.. > Judo < /li >
          < /ul >
        < /li >
      < /ul >
    < /div >

    But when I add my function override, I get this (it seems that both the old and new functions are called, the new one first for the main ul, and the old one for the inner ul):

    <div class="menu">
      < ul id="fubar" class="sf-menu" >
        < li > < a.. > About < /li >
        < li > Disciplines
          < ul id="nav" class="sf-menu" >
            < li > < a.. > Judo < /li >
          < /ul >
        < /li >
      < /ul >
    < /div >

    Anyone have any ideas what's going on? I could do the fix I want by editing the function in the thematic code, but that would defeat the purpose of having a child theme.
    Eddie

    PS - apologies for the formatting, I had to change all of my angle brackets to unicode and it looks very odd!

    Posted 9 years ago #
  10. Hey Eddie,

    try this one first:

    function remove_ulcl() {
        remove_filter('wp_page_menu','thematic_add_menuclass');
    }
    add_action('init', 'remove_ulcl');

    .. the code will remove the filter .. tested with Thematic 0.9

    Cheers,

    Chris

    Posted 9 years ago #
  11. Seems to have done the trick Chris, I'd obviously not removed the filter properly.
    Cheers,
    Eddie

    Posted 9 years ago #

RSS feed for this topic

Reply

You must log in to post.