Community Forums › Forums › Archived Forums › Design Tips and Tricks › Remove Optim widget on every page except homepage?
- This topic has 8 replies, 2 voices, and was last updated 10 years, 8 months ago by
ᴅᴀᴠɪᴅ.
-
AuthorPosts
-
July 8, 2014 at 4:25 am #113348
dsgnr
MemberHello,
I have recently purchased the Genesis framework and still trying to adjust to the way it works.I currently have an optim widget that I would like on the homepage. However, this keeps coming out on every page despite creating a custom template and a conditional in functions.php to say if not homepage, remove optim widget. I can't seem to get this to work. Is anyone able to help me out with this one?
Also, I am trying to create a full width page homepage (not boxed like the genesis default template). I have done this successfully and I am able to add a small snippet to add an extra div to create a boxed effect for a page but I am struggling to get this to work on every page except the homepage.
Its along the lines of:
// Add div.wrap inside of div#inner function child_before_content_sidebar_wrap() { echo '<div class="wrap">'; } add_action('genesis_before_content_sidebar_wrap', 'child_before_content_sidebar_wrap'); function child_after_content_sidebar_wrap() { echo '</div><!-- end .wrap -->'; } add_action('genesis_after_content_sidebar_wrap', 'child_after_content_sidebar_wrap');
Thanks in advance
July 8, 2014 at 4:50 am #113351ᴅᴀᴠɪᴅ
MemberDo you mean you are wanting a widget area to only appear on the home page? Or one particular widget inside of a widget area?
I'm trying to get my head around what you are after. With the second request.. generally the best way to make something work on every page except the home page is to have this in functions.php
add_action('genesis_after_header', 'example_function_except_home');
function example_function_except_home() {if ( is_home() )
return;- insert all your code here, all the hooks like you posted before -
}
I love helping creative entrepreneurs build epic things with WP & Genesis.
July 8, 2014 at 4:53 am #113352ᴅᴀᴠɪᴅ
MemberOh.. a more typical way of achieving full width on the home page and then boxed on every other is to create the home page using widget areas. Similar to how it is done on parallax pro child theme and epik child theme.
The widget areas run 100% across the screen, all above the .site-inner, then just a wrap is added to accommodate for the content not running into the side of the screen. This way you don't have to take apart Genesis as much and all other pages will remain untouched.
I love helping creative entrepreneurs build epic things with WP & Genesis.
July 8, 2014 at 5:11 am #113355dsgnr
MemberDavid, thank you for responding. That's basically what I have done. I edited some of the css so that I just have to add
<div class="wrap">
in order to create a box effect. However, I can only get this to work on pages I have manually entered text into and not archive pages for a custom post type for example if this makes sense.I have tried to create custom templates (like you would in a typical framework. I have previously used WP-Forge) so that the homepage is 100% the width of the browser size and I would select this template in the WP page template attribute. Then I would have a boxed template for other pages as default if this makes sense.
Having tried to create a custom template, either it doesn't show up in the attributes panel or it doesn't make a difference to the page.
In regards to the Optim widget area, I would like this only to show up on the homepage and no where else on the site. I have tried something like
if ( !is_front_page() ) { remove_action( 'genesis_optim_widget' ); }
I understand that isn't the right class for the action but that's the sorta thing I need.
July 8, 2014 at 5:43 am #113357ᴅᴀᴠɪᴅ
MemberSince Genesis is 'boxed' from the start. You're much better off just creating the front-page.php file, ensuring your home page is full width as you need it and leaving Genesis to do the rest for the rest. Otherwise your overriding what is already there. This also would solve your optim widget area problem as you can just add the hook in the front-page.php file and every other page knows nothing of it.
Ok some code to show you what I mean...
So you would create the widget area in your functions.php by adding this to the bottom...
//* Register widget area
genesis_register_sidebar( array(
'id' => 'home-optin-widget-area,
'name' => __( 'Home Optin Widget Area, ‘child’ ),
'description' => __( 'This is the optin widget area on the homepage.', 'child' ),
) );and then in front-page.php you would have something like...
<?php
/**
* Homepage template
*/add_action( 'genesis_meta', ‘child_home_genesis_meta' );
/** Add widget support for homepage. If no widgets active, display the default loop.
*/
function child_home_genesis_meta() {if ( is_active_sidebar( 'home-optin-widget-are ) {
add_action( 'genesis_after_header', ‘child_homepage_widgets' );
}
}
function child_homepage_widgets() {
genesis_widget_area( 'home-optin-widget-area', array(
'before' => '<div id="home-optin-widget-area" class="home-optin-widget-area"><div class="wrap">',
'after' => '</div></div>',
) );}
In this example the widget area called 'home optin widget area' would appear after the header ONLY on the home page.
You can then add more widgets in the same way, one after another, effectively creating yourself a full width homepage made of widget areas. And the rest of your site will remain untouched.
I love helping creative entrepreneurs build epic things with WP & Genesis.
July 8, 2014 at 5:58 am #113360ᴅᴀᴠɪᴅ
Memberof course my suggestion is if you were starting from scratch. if you already have quite a few things in place it may not be the best way.
You said you already have an optin widget area?
If so, you just need to move the code which hooks it into the theme out of functions.php and into the home page template.
I love helping creative entrepreneurs build epic things with WP & Genesis.
July 8, 2014 at 6:54 am #113371dsgnr
MemberHi David, thank you for your code above unfortunately it didn't actually make a difference to the site.
I have decided to start again with this with the genesis child theme sample instead of one I found on another blog which has given me a few ideas to try something else. I suspect it's something that I have done as I absolute positioned the optim box which then made everything else float behind, instead of underneath as you want so I think it was somewhere there that was causing me problems.
I will post my findings and maybe even put it up on github for other people for fork if it's worthwhile!
Thanks again
July 8, 2014 at 7:34 am #113374dsgnr
MemberOkay I think I'm getting there, I just need help on something else please.
I have this code in my functions.php:
// Home page widgets genesis_register_sidebar( array( 'id' => 'home-featured-full', 'name' => __( 'Home Featured Full', 'CHILD_THEME_NAME' ), 'description' => __( 'This is the featured area if you want full width.', 'CHILD_THEME_NAME' ), ) );
and this is my custom-homepage.php file:
<?php /** * Custom Front Page * Template Name: Homepage * */ if ( is_active_sidebar( 'home-featured-full' )) { remove_action( 'genesis_loop', 'genesis_do_loop' ); add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' ); add_action( 'genesis_before_content', 'sc_home_do_featured' ); add_action( 'genesis_loop', 'genesis_do_loop' ); } // Home feature widget section function sc_home_do_featured() { if ( is_active_sidebar( 'home-featured-full' )) { genesis_widget_area( 'home-featured-full', array( 'before' => '<main class="home-featured-full">', 'after' => '</main>', ) ); } } genesis(); ?>
This works the way I'd like it to however, the "home-featured-full" widget appears inside the site-inner div. I have looked to see whether I can remove_action the site-inner div and then include the home-featured code, then re-add the site-inner div in another action.
I can't seem to find anywhere in the snippets area to explain how to do this.
I have tried:
// Home feature widget section add_action ('genesis_after_header'); { function home_do_featured() { if ( is_active_sidebar( 'home-featured-full' )) { genesis_widget_area( 'home-featured-full', array( 'before' => '<main class="home-featured-full">', 'after' => '</main>', ) ); } } }
I feel like I'm close, I just need to get the home-featured div outside the site-inner width constraints.
July 13, 2014 at 6:03 pm #114182ᴅᴀᴠɪᴅ
MemberYou just need to write it like this.
// Home feature widget section add_action( 'genesis_after_header', 'home_do_featured' ); function home_do_featured() { if ( is_active_sidebar( 'home-featured-full' )) { genesis_widget_area( 'home-featured-full', array( 'before' => '<main class="home-featured-full">', 'after' => '</main>', ) ); } }
But the genesis_after_header is the correct hook. You can see here that it is full width http://genesistutorials.com/visual-hook-guide/
I love helping creative entrepreneurs build epic things with WP & Genesis.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.