Support » Theme: Customizr » Child Theme – Adding a "Header" Widget Area

  • Resolved jbush82

    (@jbush82)


    I’m creating a child theme of Customizr and with it, a plugin that enables a persistant fasebook based login / logoff. I’d like to have the login / logoff content be displayed at the top of the Customizr theme and I think the right way to do this is create a child theme with a new “header” area, in addition to “right sidebar”, “left sidebar”, “footer widget area one”, “footer widget area two”, and three “footer widget area three”.

    My problem is that I’m not exactly sure how to do this given it is my first go at it. I found the content areas within the Customizr theme (class-header-header_main.php), but I’d rather not replicate that file and modify the one section I want. As such, I’m thinking it maybe easier to create a new widget area and somehow point it to the right location.

    Thoughts?

Viewing 15 replies - 1 through 15 (of 22 total)
  • You’ve pre-empted my next snippet 🙂

    <p>To define a new widget, add the following code to your functions.php file in your child theme:</p>

    // Add a widget.
    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    	'name' => 'Extra Widget Before Header',
    	'id' => 'extra-widget',
    	'description' => 'Extra Widget Before Header',
    	'before_widget' => '<div id="%1$s" class="widget %2$s">',
    	'after_widget' => '</div>',
    	'before_title' => '<h2>',
    	'after_title' => '</h2>'
    	));
    }

    <p>You then need to hook your widget to the beginning of the header. Add the following code below the code above:</p>

    // Place the widget before the header
    add_filter ('__before_header', 'add_my_widget');
    function add_my_widget() {
    	if (function_exists('dynamic_sidebar')) {
    	dynamic_sidebar('Extra Widget Before Header');
    	}
    }

    <p>That’s it! When you go to Appearance > Widgets, you’ll find your widget there, ready to be filled with whatever you want.</p>

    You will then need to style it, of course.

    Thread Starter jbush82

    (@jbush82)

    Perfect, exactly what I was looking for.

    Thanks!

    Thread Starter jbush82

    (@jbush82)

    Just wanted to give a quick update on this… after some further thinking, I decided to change the location of the widget (at least for my purposes). Instead of placing it before the entire header, I placed it after the navbar. I did this by changing “__before_header” to “__after_navbar”… I also played around with “before_navbar” (strange that this wouldn’t have the preceding __).

    The second part of the code looks like this for placing it after the navbar but within the header:

    // Place the widget before the header
    	add_filter ('__after_navbar', 'add_my_widget');
    	function add_my_widget() {
    		if (function_exists('dynamic_sidebar')) {
    		dynamic_sidebar('Extra Widget Before Header');
    		}
    	}

    The second part of the code looks like this for placing it before the navbar but within the header:

    // Place the widget before the header
    	add_filter ('before_navbar', 'add_my_widget');
    	function add_my_widget() {
    		if (function_exists('dynamic_sidebar')) {
    		dynamic_sidebar('Extra Widget Before Header');
    		}
    	}
    B

    (@logicintl)

    @electric Feet … or if you know where to point me, please do. 🙂

    How does one go about “‘styling’ it, of course” … what is the next step?

    I want to be able to do what was done at this website … http://rvbusiness.com … where they put scrolling ad banners above the header, is that what this will allow me to do?

    Also, if you need to see what those lines of code above are doing, see it at … http://the-rv-life.com … it is, as you all say, ‘un-styled’.

    When complete will this give me a ‘widget’ drag & drop in the usual widget area?

    Also, my Customizr Child Theme did not have a functions.php file, so I made the file and put the code in this functions.php file.

    Thanks much,
    B

    B, you have an error in your functions.php. Probably you closed the php tag (?>) before
    ‘// Add a widget’

    B

    (@logicintl)

    DZ … you’ve got an amazing eye … I will repeat with care … thanks so much. B

    B

    (@logicintl)

    DZ … I repeated the process … I did a strict copy/paste of the code placed above in the string, er support thread.

    Now look see and advise.

    B

    now seems you have closed it before:
    ‘// Place the widget before the header’
    can you paste your functions.php code in pastebin: http://pastebin.com/
    and then give me the link?

    B

    (@logicintl)

    DZ,

    Ok, here you go …

    Pastebin: http://pastebin.com/FQWF26J4
    Website: http://the-rv-life.com/

    Thanks 🙂
    B

    This is all your child-theme functions.php?

    So I was wrong, you didn’t close the php closing tag before the actual end, you never opened it
    But why you have the code 2 times, and what happend to the widget area declaration ?????
    Should be:

    <?php
    // Add a widget.
    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    	'name' => 'Extra Widget Before Header',
    	'id' => 'extra-widget',
    	'description' => 'Extra Widget Before Header',
    	'before_widget' => '<div id="%1$s" class="widget %2$s">',
    	'after_widget' => '</div>',
    	'before_title' => '<h2>',
    	'after_title' => '</h2>'
    	));
    }
      // Place the widget before the header
                add_filter ('before_navbar', 'add_my_widget');
                function add_my_widget() {
                        if (function_exists('dynamic_sidebar')) {
                        dynamic_sidebar('Extra Widget Before Header');
                        }
                }

    B

    (@logicintl)

    DZ,

    Hey, I did a strict copy/paste of what was in this thread, as instructed to do above.

    The instructions said to put the second set of code in, so I followed the instructions.

    Now I will follow your instructions, to the letter, because I cannot operate with full knowledge on this stuff, just yet.

    So, your help, I’d be lost without it.

    Thx, 🙂
    B

    But you missed the first part, or better you deleted it, and you don’t have to use both hook “__after_navbar” and “before_navbar” you have to chose one of them, if you don’t want that are to be printed twice.
    Also sorry, I don’t think “before_navbar” exists, try __before_navbar, but where do you want to place it???

    B

    (@logicintl)

    DZ,

    YIPPEEEE … and viola, there’s a new widget, so cool, oh boy, thank you, thank you, thank you.

    There is now a Widget in the usual widget area. Ok, now how do I put stuff in there?

    I cannot put arbitrary words in that box, like you can with a text widget. So, how does this widget work?

    Thx! 🙂
    B

    B

    (@logicintl)

    DZ,

    I copy/pasted exactly what you put up above.

    Has something now changed?

    Would you please re-paste the bunch of code and I will re-copy/paste whatever you tell me to copy/paste.

    I have no idea what the pieces/parts of the code mean as yet, I am learning bits and bits as I go along. I don’t know what goes where or why.

    B

    Don’t get what you mean B.
    You haven’t create a widget, but a widget area, you should see it in Widgets, named ‘Extra Widget Before Header’

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Child Theme – Adding a "Header" Widget Area’ is closed to new replies.