Community Forums › Forums › Archived Forums › Design Tips and Tricks › Adding Blog Sidebar
Tagged: blog sidebar
- This topic has 6 replies, 2 voices, and was last updated 8 years, 4 months ago by michiganseo.
-
AuthorPosts
-
April 30, 2016 at 5:59 am #184734michiganseoMember
Hi All,
I'm trying to add a sidebar for all my blog posts that would be different than my pages. I came across the following blog post that sounded exactly perfect: http://www.billerickson.net/code/blog-sidebar-genesis/. It did successfully remove the primary sidebar from my blog posts. However, when I go to appearance>widgets there is no "blog" sidebar listed in which I can put my widgets... Any body know what may be missing?
Thanks!
May 1, 2016 at 5:25 am #184759Victor FontModeratorTry the Genesis Simple Sidebars plugin. It's easier.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?May 1, 2016 at 11:12 am #184766michiganseoMemberHi Victor,
Thanks for that. I definitely do use the Genesis Simple Sidebars plugin. However, my goal is to have all blog posts "default" to a "blog" sidebar -- and all existing posts to be automatically converted over without going into every single post and making that change. Thanks for your help.May 3, 2016 at 5:56 am #184892Victor FontModeratorGenesis Simple Sidebars works on a page level, not post level. Posts are displayed by the single.php template. You can call sidebars dynamically in functions.php with the following code:
function vmf_remove_sidebar() { if ( is_single() || is_category() || is_tag() ) { //set your conditionals here remove_action( 'genesis_sidebar', 'ss_do_sidebar' ); //removes Simple Sidebar remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); //removes Genesis Default sidebar add_action( 'genesis_sidebar', 'vmf_add_sidebar' ); //adds alternative sidebar in function below } } //Alternative Sidebar function vmf_add_sidebar() { dynamic_sidebar( 'blog-sidebar' ); //add in the ID of the sidebar you want to replace it with } add_action( 'genesis_before_sidebar_widget_area', 'vmf_remove_sidebar' );
Be careful with the conditionals. I didn't add one for the blog page itself, but you can lookup is_page in the codex if you need it. Sice you said you are using Simple Sidebars, I added a line to remove that action so there's no conflict. If you don't need it, you should comment it out.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?May 3, 2016 at 7:14 am #184895michiganseoMemberHi Victor,
Thank you. I will try that. Is this an all or nothing proposition -- meaning if I add this code, I will no longer be able to use the Genesis Simple Sidebar on posts? Just curious. I assume I won't be able to, but just wanted to double-check.May 3, 2016 at 7:49 am #184899Victor FontModeratorThe code I gave you removes Simple Sidebars from all posts in favor of your own custom sidebar. You can limit it to specific post categories or tags. Look up is_category and is_tag in the codex to learn how to do this. There is no WordPress conditional that I know of that tests whether or not a sidebar has been attached to a specific post or page. The WordPress sidebar conditionals test whether a sidebar has a widget or not. If there is a widget attached to a sidebar, the sidebar is considered active regardless of the origin of the sidebar. If you want something that isn't all or nothing, you'll have to either futrther filter the conditionals or create your own page template(s) that use the sidebars you want for the conditions you specify.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?May 3, 2016 at 10:32 am #184904michiganseoMemberThank you, Victor! Much appreciated!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.