#content-wrap

This topic is: resolved

This topic contains 3 replies, has 2 voices, and was last updated by  Gary Jones 1 year, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #35303

    mcnutty
    Participant
    Post count: 5

    I am trying to create a div wrap around #content.hfeed. What I currently have in my theme is this:

    <div id=”content-sidebar-wrap”>

    <div id=”content” class=”hfeed”></div><!– end #content –>

    <div id=”sidebar” class=”sidebar-widget-area”></div>

    </div><!– end #content-sidebar-wrap –>

    What I am trying to achieve is this:

    <div id=”content-sidebar-wrap”>

    <div id=”content-wrap”>

    <div id=”content” class=”hfeed”></div><!– end #content –>

    </div><!–end #content-wrap–>

    <div id=”sidebar” class=”sidebar-widget-area”></div>

    </div><!– end #content-sidebar-wrap –>

    This is my code in functions.php:

    add_action(‘genesis_before_content’, ‘add_conent_wrap’ );
    function add_conent_wrap() {
    echo “<div id=’content-wrap’>”;
    }

    add_action(‘genesis_after_content’, ‘end_conent_wrap’ );
    function end_conent_wrap() {
    echo “</div> <!–end #content-wrap–>”;
    }

    This is the result:

    <div id=”content-sidebar-wrap”>

    <div id=content-wrap>

    <div id=”content” class=”hfeed”></div><!– end #content –>

    <div id=”sidebar” class=”sidebar-widget-area”></div>

    </div> <!–end #content-wrap–>

    </div><!– end #content-sidebar-wrap –>

    I greatly appreciate your feedback

    #35371

    Gary Jones
    Moderator
    Post count: 686

    Add a priority to the second add_action() call, to make the function happen earlier than the function that adds the sidebars.

    [php]
    add_action( ‘genesis_after_content’, ‘end_conent_wrap’, 5 );
    [/php]


    Changes in Genesis 2.1 – the ultimate guide to every single change in Genesis Framework 2.1 and 2.1.1 (all 88 of them!) | @GaryJ

    #35478

    mcnutty
    Participant
    Post count: 5

    That worked perfectly! Can you explain why there needs to be a priority added and why the it is 5? I am new to the Genesis Framework and am really excited about customizing themes, but because I am used to editing the backend php I am having some problems.

    #35489

    Gary Jones
    Moderator
    Post count: 686

    Glad it worked :-)

    The relevant bit of background reading can be found at http://codex.wordpress.org/Function_Reference/add_action

    In short, when two functions are hooked in to the same hook, WP needs a way to work out what order they should be run. By default, it’s first come, first served, which is what was happening with your original situation – that is, Genesis was being processed and added the sidebar in at that point, and later on your child theme was being processed and adding in the closing tag.

    So that the order can be changed as required (just like we needed to do here), then the priority argument was added, with the default as 10. So what WP really does is check for anything hooked to that hook with priority 1, then processes them in the order they were given. Then it looks at priority 2 and processes them in order, and so on. [*] So here, we’re saying that YOUR function should go at priority 5 (an arbitrary number that’s less than 10), which means it happens well before the Genesis function at priority 10. You could have used priority 9, 8, 7 and so on, but 5 is as good a number as any, and means anything else you want to squeeze on to the same hook can go on the intervening numbers.

    [*] It doesn’t actually check each priority like that – it just looks at what functions are hooked in, and sorts them by priority first, but I think the above makes it clearer to imagine.


    Changes in Genesis 2.1 – the ultimate guide to every single change in Genesis Framework 2.1 and 2.1.1 (all 88 of them!) | @GaryJ

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.