Introduction
The theme framework does have a pretty intricate widget area system, however it doesn’t mean that you have to use it. Have you ever been in the midst of creating a theme for yourself and just wanted to hardcode your sidebar? — I know I have.
I’d never suggest this approach if you’re making a theme for public distribution, but if this is a just for a personal site, there’s nothing wrong with straying from widgets if that’s what you’re wanting to do.
Accomplishing this isn’t as easy as you would think. Your Parent theme does contain the standard sidebar-left.php
and sidebar-right.php
files that you could copy to your Child theme to override; however, if you do this, your custom-coded sidebars will not easily fall in-line with the framework’s sidebar layout system.
Your custom sidebar functions
First off, let’s assume you want to keep your actual code that displays your left and right sidebars out of the muck that I’ll be giving you in the next section of this article. So we’ll just create two functions, one for each sidebar.
/** * Your custom code for the left sidebar */ function my_left_sidebar() { echo 'This is the left sidebar.'; } /** * Your custom code for the right sidebar */ function my_right_sidebar() { echo 'This is the right sidebar.'; }
And then, later, you can obviously expand on these functions to include whatever you’re going for.
Replacing framework sidebars
Within your Parent theme’s sidebar-left.php
and sidebar-right.php
files, we’re utilizing the action hook “themeblvd_sidebars” to display the appropriate sidebars depending on the current sidebar layout. The default hooked function that does all of this is called themeblvd_fixed_sidebars
.
So, we need to create our own function to replace the framework’s default themeblvd_fixed_sidebars
. Let’s call this my_custom_sidebars
and set it up as follows.
/** * Call our sidebar functions based on the * current position and current sidebar layout. */ function my_custom_sidebars( $position ) { // Get current sidebar layout $layout = themeblvd_config( 'sidebar_layout' ); if( $position == 'left' ) { // Display any sidebars to be located on the LEFT // based on the current sidebar layout. // Display the left sidebar if( $layout == 'sidebar_left' || $layout == 'double_sidebar' || $layout == 'double_sidebar_left' ) { do_action( 'themeblvd_fixed_sidebar_before', 'left' ); my_left_sidebar(); do_action( 'themeblvd_fixed_sidebar_after' ); } // Display the right sidebar if there is a // double sidebar over on the left. if( $layout == 'double_sidebar_left' ) { do_action( 'themeblvd_fixed_sidebar_before', 'right' ); my_right_sidebar(); do_action( 'themeblvd_fixed_sidebar_after' ); } } else if( $position == 'right' ) { // Display any sidebars to be located on the RIGHT // based on the current sidebar layout. // Display the left sidebar if there is a // double sidebar over on the right. if( $layout == 'double_sidebar_right' ) { do_action( 'themeblvd_fixed_sidebar_before', 'left' ); my_left_sidebar(); do_action( 'themeblvd_fixed_sidebar_after' ); } // Display the right sidebar if( $layout == 'sidebar_right' || $layout == 'double_sidebar' || $layout == 'double_sidebar_right' ) { do_action( 'themeblvd_fixed_sidebar_before', 'right' ); my_right_sidebar(); do_action( 'themeblvd_fixed_sidebar_after' ); } } }
Now that we’ve created our custom function, we need to hook it in. So, we’ll first remove the default hooked function and then add in our new my_custom_sidebars
function.
remove_action( 'themeblvd_sidebars', 'themeblvd_fixed_sidebars' ); add_action( 'themeblvd_sidebars', 'my_custom_sidebars' );
Conclusion
Here’s the final code which you can copy and paste as a starting point. What I’ve tried to do for you is isolate the complicated stuff to its own function so you can just worry about the functions at the top of snippet to actually display your custom sidebars.
// Your custom code for the left sidebar function my_left_sidebar() { echo 'This is the left sidebar.'; } // Your custom code for the right sidebar function my_right_sidebar() { echo 'This is the right sidebar.'; } // Call our sidebar functions based on the // current position and current sidebar layout. function my_custom_sidebars( $position ) { // Get current sidebar layout $layout = themeblvd_config( 'sidebar_layout' ); if( $position == 'left' ) { // Display any sidebars to be located on the LEFT // based on the current sidebar layout. // Display the left sidebar if( $layout == 'sidebar_left' || $layout == 'double_sidebar' || $layout == 'double_sidebar_left' ) { do_action( 'themeblvd_fixed_sidebar_before', 'left' ); my_left_sidebar(); do_action( 'themeblvd_fixed_sidebar_after' ); } // Display the right sidebar if there is a // double sidebar over on the left. if( $layout == 'double_sidebar_left' ) { do_action( 'themeblvd_fixed_sidebar_before', 'right' ); my_right_sidebar(); do_action( 'themeblvd_fixed_sidebar_after' ); } } else if( $position == 'right' ) { // Display any sidebars to be located on the RIGHT // based on the current sidebar layout. // Display the left sidebar if there is a // double sidebar over on the right. if( $layout == 'double_sidebar_right' ) { do_action( 'themeblvd_fixed_sidebar_before', 'left' ); my_left_sidebar(); do_action( 'themeblvd_fixed_sidebar_after' ); } // Display the right sidebar if( $layout == 'sidebar_right' || $layout == 'double_sidebar' || $layout == 'double_sidebar_right' ) { do_action( 'themeblvd_fixed_sidebar_before', 'right' ); my_right_sidebar(); do_action( 'themeblvd_fixed_sidebar_after' ); } } } remove_action( 'themeblvd_sidebars', 'themeblvd_fixed_sidebars' ); add_action( 'themeblvd_sidebars', 'my_custom_sidebars' );