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*

How to add a secondary menu to Attitude Pro WordPress theme?

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #2890
    jnasevich
    Participant

    I’m trying to add a secondary menu to the Attitude Pro theme. I’ve created a child theme, and I’m able to edit my child theme’s functions.php file so the secondary menu appears in the WordPress dashboard. The challenge now is to make it appear on my web site’s front end.

    Attitude theme’s header.php invokes “attitude_header” action which, as the comment in the code from header.php describes, is hooked to function “attitude_headerdetails”. Function “attitude_headerdetails” can be found in the following file:
    /wp-content/themes/attitude-pro/library/structure/header-extensions.php

    I tried making a copy of header-extensions.php file in my child theme, and then edited function “attitude_headerdetails” so it will display additional menus. However, changes to the child’s version of the file had no effect, although I’m not entirely sure why. I would guess that the parent’s version of the file gets loaded after the child’s version, so the parent’s version overrides anything done in the child’s version of the file. That means I have to edit the parent’s version of the file directly which risks the changes being lost if the theme is updated. Yuk! Is there a better way to do this???

    #2901
    Sanjip Shah
    Participant

    @jnasevich Only the template files like header.php, index.php, archive.php etc created in the child theme will replace the same file of the parent theme. But creating the functional files like header-extensions.php with same same path in the child theme will not overwrite the parent function. There is other way for this. To learn about how the functions of parent theme are unhooked from an action hook and how a function from child theme is added to action hook you can visit this link http://themeshaper.com/2009/05/25/action-hooks-wordpress-child-themes/. Below is an example of how its done. Put this code in the functions.php file of the child theme.
    add_action( ‘init’, ‘attitude_remove_parent_function’ );

    /**
    * Removes parent function attached to hook
    */
    function attitude_remove_parent_function(){
    remove_action( ‘attitude_header’, ‘attitude_headerdetails’, 10 );
    }
    
    add_action( ‘attitude_header’, ‘attitude_child_headerdetails’, 10 );
    /**
    * Add your custom function
    */
    function attitude_child_headerdetails() {
    // Copy all the content inside the attitude_headerdetails function of parent theme, paste here and make necessary changes here.
    }

    Hope this helps you.

    #2950
    jnasevich
    Participant

    @sanjipshah, thank you. Other than getting tripped up by mismatched quotation marks around names of actions and function names (I had to use straight quotation marks – I forgot how fussy PHP can be), your suggestion allows me to do what I need to do. Now, however, the controls in the Theme Options section of the WordPress dashboard no longer work. For example, in the Custom Header section, if I try to change the Header Menu Position from the default/left side to the right side and then click on the Save All Changes button, I get an error message saying, “Warning: Cannot modify header information – headers already sent by (output started at ./wp-content/themes/attitude-pro-child/functions.php:16) in ./wp-includes/pluggable.php on line 876.” I get the same error message if I try to change any other option in Theme Options section of the WordPress dashboard.

    Line 16 of my child theme’s functions.php is the start of the PHP code that removes parent’s attitude_headerdetails() function from attitude_header hook and replaces it with my own attitude_child_headerdetails() funtion. Line 876 of pluggable.php is the following line from function wp_redirect() in WordPress 3.5.2 (I have not upgraded to WordPress 3.6 yet):
    header(“Location: $location”, true, $status);

    Is it possible to continue to use dashboard controls even after unhooking the Attitude theme’s attitude_headerdetails() function and replacing it with my own attitude_child_headerdetails() funtion? If so, how?

    #2998
    Sanjip Shah
    Participant

    @jnasevich Making a child theme can be very difficult if you don’t have the proper knowledge of it and can mess the whole the functioning and flow of the theme. I think this is the same in your case as well. I strongly suggest you to hire to developer to make the child theme or learn more about child themes yourself, try it on sample projects and then work on the main project.
    As I said earlier: Copy all the content inside the attitude_headerdetails function of parent theme, paste it in the attitude_child_headerdetails. Then make you customization there, but when you are making the customization you need to completely understand the parent theme as well so you won’t break the theme and functioning.

    #3024
    jnasevich
    Participant

    @sanjipshah Child theme is extremely easy to make. I have made the changes you suggested and copied content inside the attitude_headerdetails function of parent theme, pasted it in the attitude_child_headerdetails. In fact, I have even reverted to a version without any customizations. As soon as one removes the parent function attached to the attitude_header hook, the controls in the Theme Options section of the WordPress dashboard no longer work. Please try this yourself, and let me know if the controls work for you:
    1 Create a child theme.
    2 Copy all the content inside the attitude_headerdetails function of parent theme, paste it in the attitude_child_headerdetails in child theme’s functions.php. DO NOT make any customizations. Unhook parent’s attitude_headerdetails and add attitude_child_headerdetails.
    3 Go to WordPress dashboard’s Theme Options section and change something, then try to save it. You will get error message similar to the one I had previously described.

    Now that you have seen this yourself, I’ll ask again. Is it possible to continue to use dashboard controls even after unhooking the Attitude theme’s attitude_headerdetails() function and replacing it with my own attitude_child_headerdetails() funtion? If so, how? I would prefer not to debug your code for you.

    #3033
    jnasevich
    Participant

    I found blank spaces following one of the ?> <?php pairs in the Attitude theme’s attitude_headerdetails() function in header-extensions.php. When I copied this code into my own attitude_child_headerdetails() function and subsequently tried to save changes to the header, WordPress puked on it and generated the “Cannot modify header information – headers already sent by…” error message. Removing the errant blank spaces from the copied code eliminates the problem, and I’m now able to customize the child theme while maintaining use of the controls in the Theme Options section of the WordPress dashboard. Please fix this in the next release of the Attitude theme.

    #3048
    Sanjip Shah
    Participant

    @jnasevich Please add this code add_action( ‘init’, ‘attitude_remove_parent_function’ ); just above the code that I previously provided. Just before this part

    /**
    * Removes parent function attached to hook
    */
    function attitude_remove_parent_function(){
    remove_action( ‘attitude_header’, ‘attitude_headerdetails’, 10 );
    }

    Hope this will solve your issue.

    #3060
    jnasevich
    Participant

    I already had that, of course. As I described in my previous post, problem was resolved when I removed the errant spaces between ?> <?php tags from the code that I had copied from the Attitude theme’s attitude_headerdetails() function in header-extensions.php. That eliminated the “Cannot modify header information – headers already sent by…” error message. Please fix this in the next release of the Attitude theme.

    #3075
    Sanjip Shah
    Participant

    @jnasevich Thanks for sharing. 🙂

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.