Community Forums › Forums › Archived Forums › General Discussion › Add Feature Image before Content
Tagged: Add Widget, feature box, hook, register widget
- This topic has 6 replies, 2 voices, and was last updated 8 years, 4 months ago by jshinault.
-
AuthorPosts
-
July 26, 2016 at 1:54 pm #190239jshinaultMember
Hi. I've been trying to add a feature box before my content on my homepage. I know I need to add a widget, but directions around here are very vague for me (since I'm not an expert in code). I know I need to register a new widget using the following code:
//* Register after post widget area genesis_register_sidebar( array( 'id' => 'after-post', 'name' => __( 'After Post', 'themename' ), 'description' => __( 'This is a widget area that can be placed after the post', 'themename' ), ) );
But I don't know how to make it work for my website... Then I also know I need to use genesis_before_content hook, but again, I'm not sure where to place it.
Could someone please help me out?
http://www.joannashinault.comJuly 26, 2016 at 7:48 pm #190256Genesis DeveloperMemberTry this code. Add it in your functions.php file.
//* Register after post widget area genesis_register_sidebar( array( 'id' => 'after-header', 'name' => __( 'After Header', 'themename' ), 'description' => __( 'This is a widget area that can be placed after the site header', 'themename' ), ) ); add_action( 'genesis_after_header', 'themename_after_header', 20); function themename_after_header() { if( ! is_home() ) return; if( is_active_sidebar( 'after-header' ) ): genesis_widget_area( 'after-header', array( 'before' => '<div class="after-header widget-area clearfix" id="after-header"><div class="wrap">', 'after' => '</div></div>', ) ); endif; }
Explaining:
1. Creating the new widget area
2. Using the "genesis_after_header" hook and adding the new widget area after the "site-header" markup
3. Returning early If user is not visiting the home page. is_home() function will return true if you are on home page.if( ! is_home() ) return;
4. If you activate the "After Header" widget area, then it will show the widget area after header. is_active_sidebar() is checking that a sidebar is active or not.
5. Echoing the widget area by genesis_widget_area() function which is taking 2 parameters. One is widget ID as a string and another one is HTML markup as an array.Hope it will help you.
July 26, 2016 at 8:51 pm #190260jshinaultMemberThanks for the quick reply! Alright, I added the code from above, but how do I know if it worked or not? I don't see it in my widgets area... Am I missing something? Thanks again!
July 26, 2016 at 9:07 pm #190262jshinaultMemberAlso, I do want the widget to go above content and not below header since I want my feature image below the navigation bar. But I think I know how to replace the code to work with that.
July 26, 2016 at 9:15 pm #190264Genesis DeveloperMemberYou are wanting the widget area above the every post content?
If you did not add the widget in new widget area from your dashboard then it will not appear on your home page.
July 27, 2016 at 12:54 pm #190313jshinaultMemberI want the widget below the navigation bar and above the first post on my homepage only.
I do not see a new widget area on my dashboard...
July 29, 2016 at 10:00 am #190446jshinaultMemberAny ideas? I really need this set in place on my site as soon as possible....
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.