Community Forums › Forums › Archived Forums › Design Tips and Tricks › #content-wrap
- This topic has 3 replies, 2 voices, and was last updated 11 years ago by Gary Jones.
-
AuthorPosts
-
April 13, 2013 at 6:43 pm #35303mcnuttyMember
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
April 14, 2013 at 6:49 am #35371Gary JonesMemberAdd a priority to the second add_action() call, to make the function happen earlier than the function that adds the sidebars.
add_action( ‘genesis_after_content’, ‘end_conent_wrap’, 5 );
WordPress Engineer, and key contributor the Genesis Framework | @GaryJ
April 14, 2013 at 4:22 pm #35478mcnuttyMemberThat 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.
April 14, 2013 at 5:18 pm #35489Gary JonesMemberGlad 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.
WordPress Engineer, and key contributor the Genesis Framework | @GaryJ
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.