Archived topic
Sidebar not showing on CPT
4 replies · Started by Matthew on September 19, 2020
Hi,
I may have missed post on this already but didn't see one in the search.
I have a CPT (wpfc_sermon) generated by a third-party module (Sermon Manager - https://en-gb.wordpress.org/plugins/sermon-manager-for-wordpress/).
I have managed to integrate it into GP using module provided filters and GP provided filters so that it displays Archive and Single as a GP Archive & Single. However, I cannot get a sidebar to display on Archive page or Single posts, and I'm not sure why.
Sidebars work on normal posts, just not on this CPT.
The code for integration is below, do you see anything obvious.
add_filter( 'generate_blog_columns', function ( $columns ) {
if ( is_post_type_archive( 'wpfc_sermon' ) ) {
return true;
}
return $columns;
});
add_filter( 'generate_sidebar_layout', function( $layout ) {
// If we are viewing search results, set the sidebar
if ( is_post_type_archive( 'wpfc_sermon' ) || is_page_template( 'content-sermon-single.php' ) || get_post_type() ==='wpfc_sermon' ) {
return 'right-sidebar';
}
// Or else, set the regular layout
return $layout;
} );
add_filter( 'sm_templates_wrapper_start' , function ($content) {
ob_start();
?>
<div id="primary" <?php generate_do_element_classes( 'content' ); ?>>
<main id="main" <?php generate_do_element_classes( 'main' ); ?>>
<?php
do_action( 'generate_before_main_content' );
return ob_get_clean();
});
add_filter( 'sm_templates_wrapper_end' , function ($content) {
ob_start();
do_action( 'generate_after_main_content' );
?>
</main><!-- #main -->
</div>
<?php
do_action( 'generate_after_primary_content_area' );
generate_construct_sidebars();
return ob_get_clean();
});
Sorry, forgot to add the generate_get_layout() does return 'right-sidebar' for the CPT.
Hi there,
Any chance you can link us to the site in question?
You can use the private information field.
Let me know :)
I have attached those details.
Just as an update if I removed the filters that wrap the CPT in GP container then the sidebar shows.
Hi there,
Are you sure the template hooks are filters (add_filter) and not actions (add_action)? Do they have instructions on integrating themes with their plugin that we can check out?