Community Forums › Forums › Archived Forums › Design Tips and Tricks › function to add sidebar to a post type
Tagged: ss_do_sidebar
- This topic has 5 replies, 3 voices, and was last updated 6 years, 5 months ago by Brad Dalton.
-
AuthorPosts
-
November 3, 2017 at 9:19 am #213237smallfishParticipant
Ive followed several suggestions from around the web to create a function that adds a specific sidebar to a post type. The function is working in that it adds the sidebar ok but i cant get it to remove the widgets that appear in the primary sidebar. The inserted sidebar "contact" is set up in Genesis simple sidebars and works fine
Any one have a thought as to whats wrong? Here's my function
If you look at the url the list of FAQ's should be there The categories widget and the one that says "this is the primary sidebar" are in the primary sidebar
Thanks
function dsi_update_faq_sidebar() {
if ( get_post_type() =='faq') { // Here "faq" is a slug name for my CPT
remove_action( 'genesis_sidebar', 'ss_do_sidebar' ); //remove the default genesis sidebar
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); // and the default wordpress one not sure about this
add_action( 'genesis_sidebar', 'dsi_add_contact_sidebar' ); //add an action hook to call the function for my custom sidebar
}
}//Function to output my custom sidebar
function dsi_add_contact_sidebar() {
dynamic_sidebar( 'contact' ); // id of sidebar is contact
}add_action('get_header','dsi_update_faq_sidebar');
http://digitalsilverimaging.com/wp2017/faq/archival-life-of-prints/November 3, 2017 at 11:09 am #213239Victor FontModeratorThe code commented as remove the default Genesis sidebar is not removing the default Genesis sidebar. The next line that you have commented as removing the default WordPress sidebar is removing the default Genesis sidebar. Unless you have a customization that is adding a sidebar in a function named ss_do_sidebar, that line is not doing anything. You also don't need the get_header action.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?November 3, 2017 at 7:59 pm #213250smallfishParticipantVictor thanks for your comments Ive removed the ss_do_sidebar line I added that because im using simple sidebars and i though that might remove the genesis primary one but your right it doesnt mattter.
If I remove
add_action('get_header','dsi_update_faq_sidebar');
The new sidebar doesnt appear- just the genesis primary.What i don't understand is why it's there, shouldn't this
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
remove it
November 4, 2017 at 9:01 am #213258Victor FontModeratorIf you're using the Simple Sidebars plugin, it's very likely overriding the Genesis defaults. The code you're using should work if Simple Sidebars is disabled. I'm not sure how I would do this with SS enabled.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?November 4, 2017 at 7:29 pm #213273smallfishParticipantWas my belief that this line removed the simple sidebar sidebar- I feel like ive used it in the past and see other people talking about it in various functions here and there
remove_action( 'genesis_sidebar', 'ss_do_sidebar' );
Not sure why one or the other doesn't do it
November 7, 2017 at 11:36 am #213363Brad DaltonParticipantThis works :
add_action( 'get_header', 'remove_primary_sidebar' ); function remove_primary_sidebar() { remove_action( 'genesis_sidebar', 'ss_do_sidebar' ); }
Then you need to add your custom sidebar back using another function.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.