Hi there,
The sidebar implementation depends on what theme, and that standard depends on the templates.
Please ignore the above procedures and let’s do it this way.
- Go to
Appearance > Sidebars
and add a sidebar as mentioned in this article.
- Write down the ID of the sidebar you created for future reference, example, the ID is in this screenshot
https://tco-forum-uploads.s3.amazonaws.com/original/3X/2/9/29461e867b9e9e49ff0417f1d8b119bbff7744f7.jpg
- Go to
Appearance > Widgets
and assign whatever widget you like to the sidebar which you have created in the first step.
The above 3 steps are optional so further procedures may vary, let’s continue
- If you don’t have any child theme yet, then please install one and activate it (you may find more information here https://theme.co/apex/forum/t/setup-how-to-setup-child-themes/57 )
- Please add this code to your child theme’s functions.php
function x_get_content_layout() {
$content_layout = x_get_option( 'x_layout_content' );
if ( $content_layout != 'full-width' ) {
if ( is_home() ) {
$opt = x_get_option( 'x_blog_layout' );
$layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
} elseif ( is_singular( 'post' ) ) {
$meta = get_post_meta( get_the_ID(), '_x_post_layout', true );
$layout = ( $meta == 'on' ) ? 'full-width' : $content_layout;
} elseif ( x_is_portfolio_item() ) {
$layout = 'full-width';
} elseif ( x_is_portfolio() ) {
$meta = get_post_meta( get_the_ID(), '_x_portfolio_layout', true );
$layout = ( $meta == 'sidebar' ) ? $content_layout : $meta;
} elseif ( is_page_template( 'template-layout-content-sidebar.php' ) ) {
$layout = 'content-sidebar';
} elseif ( is_page_template( 'template-layout-sidebar-content.php' ) ) {
$layout = 'sidebar-content';
} elseif ( is_page_template( 'template-layout-full-width.php' ) ) {
$layout = 'full-width';
} elseif ( is_archive() ) {
if ( x_is_shop() || x_is_product_category() || x_is_product_tag() ) {
$opt = x_get_option( 'x_woocommerce_shop_layout_content' );
$layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
} else {
$opt = x_get_option( 'x_archive_layout' );
$layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
}
} elseif ( x_is_product() ) {
$layout = 'full-width';
} elseif ( x_is_bbpress() ) {
$opt = x_get_option( 'x_bbpress_layout_content' );
$layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
} elseif ( x_is_buddypress() ) {
$opt = x_get_option( 'x_buddypress_layout_content' );
$layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
} elseif ( is_404() ) {
$layout = 'full-width';
} else {
$layout = $content_layout;
}
} else {
$layout = $content_layout;
}
if ( is_home() || is_singular( 'post' ) ) {
$layout = 'content-sidebar';
}
return $layout;
}
Note: Append it to the child theme’s functions.php and don’t overwrites what’s in there. And you will have to use FTP or your hosting’s file manager to edit the child theme’s functions.php
This code bypass the settings you have in X > Launch > Options > Blog
and X > Launch > Options > Layout and Design
. And because blog layout usually inherits the layout from Layout and Design
, you wouldn’t see any difference if the global layout is set to full-width (no sidebar). The workaround is that code
- Remember the first 3 procedures above?
-------- If you choose to follow those 3 procedures, then add this code to your child theme’s functions.php too
function assign_custom_sidebar($sidebar){
if ( is_single() ){
return 'ups-sidebar-blabla';
}
return $sidebar;
}
add_filter( 'ups_sidebar', 'assign_custom_sidebar');
You must also change the ups-sidebar-blabla
with the ID of the sidebar you created. Like from here
-------- If you choose to ignore those 3 procedures, then no need for additional codes. What you need to do is add your widgets to your MAIN SIDEBAR
in Admin > Appearance > Widgets
. If you don’t define custom sidebar and ID then it will use the main sidebar automatically .
Hope these helps