Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to enable sidebar for homepage only when home page is widgetised?
- This topic has 7 replies, 2 voices, and was last updated 5 years, 2 months ago by BrendaGaelSmith.
-
AuthorPosts
-
July 7, 2019 at 10:39 pm #492179BrendaGaelSmithParticipant
I would like to enable a sidebar for the home page only and have the balance of the site full width by default.
The home page is widgetised. If full width is checked in theme settings, the sidebar does not show up on the home page. If Content, Sidebar is checked in theme settings, the full width setting has to be manually set for all other pages.
Is it possible to enable the primary sidebar for the home page only?
http://serendipitypatchwork.com.au/sandbox3July 7, 2019 at 11:36 pm #492180Brad DaltonParticipantWhat you can do is add 1 line of PHP code to your child themes front-page.php file.
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar' );
Another option is to add code to your child themes functions file which enables you to conditionally change the layout.
July 8, 2019 at 3:02 pm #492199BrendaGaelSmithParticipantThat snippet worked perfectly. Thank you!
July 8, 2019 at 7:26 pm #492205BrendaGaelSmithParticipantActually, that snippet worked OK with the Lifestyle Pro theme but not with the Foodie Pro theme. I will have to try the conditional layout coding but that will stretch me.
July 8, 2019 at 11:24 pm #492207Brad DaltonParticipantI tested both solutions in the Foodie Pro themes front-page.php file and the functions.php file and both work.
Note : When using the 2nd solution, you will need to use the is_front_page() conditional tag.
July 13, 2019 at 11:32 pm #492355BrendaGaelSmithParticipantThanks Brad.
I set up a fresh Foodie Pro installation at http://www.serendipitypatchwork.com.au/sandbox2; changed the settings so that the static sample page is the home page and changed the layout in theme settings to full width.
Still no joy when adding the snippet to the front-page.php file. That is to say, no sidebar re-appeared on the home page.
As for adding conditional coding to the functions.php file, I get the beginning part and the if part but am not clear on how to string it all together without getting syntax errors. I tried all sorts of combinations. For example, the following code simply placed the sidebar on the left and not just on the home page but the blog page too.
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_content' ); { if (is_front_page()) { $opt = 'content-sidebar'; return $opt; } }
Any further guidance is welcome. Thank you.
July 13, 2019 at 11:51 pm #492356Brad DaltonParticipant1. I never mentioned changing any settings meaning i would leave the Reading settings as default.
2. Please check your code because it doesn't look like the code i posted in the tutorial.
July 14, 2019 at 4:46 pm #492365BrendaGaelSmithParticipantSuccess! These are the steps I took with the Foodie Pro theme:
- I went back and inserted content in the front page widgets to enable the front page.
- I changed the Reading settings back to default so that home page displays latest posts.
- I changed the site to default to full-width content via Customise>Theme Settings.
- I tried adding the one line snippet to the front-page.php file but it still did not work for me in either the fresh install or the work-in-progress install.
- I added the code below to the functions.php file and the sidebar reappeared on the home/front page of both sites
add_filter( 'genesis_pre_get_option_site_layout', 'change_layout_blog_page'); function change_layout_blog_page( $opt ) { if (is_front_page() ) { $opt = 'content-siderbar'; return $opt; } }
I was confused as the tutorial link contains coding for a variety of scenarios and initially I did not associate "change_layout_blog_page" with the home page but I got there in the end. Thank you for your patience and guidance.
-
AuthorPosts
- The topic ‘How to enable sidebar for homepage only when home page is widgetised?’ is closed to new replies.