Thesis Tip — Control Sidebars With Custom Fields In Thesis Theme For WordPress

WordPress custom fields allow the post / page author to control the appearance, display or additional content on specific post(s) / page(s). Ranging from simple addition of meta-data to controlling the appearance of a particular post / page, WordPress custom fields come in handy for customizing the WordPress theme. One such instance is controlling the sidebars with custom fields.

You can create a custom field to remove the sidebars from specific pages / posts. You can however do the same thing with the help of No Sidebar template for pages or by hard coding the post ID in custom_functions.php. Check out the tutorial for removing the sidebars here. While it is fairly simple to use No Sidebars template for pages, hard coding the post ID every time you are willing to remove the sidebars from the single posts is practically not feasible. Using the custom fields is a better alternative for this one — just create it ones and use it anytime, for any post.

Creating and using the custom fields is a simple three step process.

  1. Add New Custom Field: Scroll down to Custom Fields section in the post / page editor and push Add Custom Field to add new custom field. It accepts the key / value pair. Provide the name for the custom field, “nosidebar” in this case with an arbitrary value to store as its value.
  2. Define The Function For New Custom Field: Once you have created the custom field, define the function for the custom field — to explicitly state the purpose of the newly created custom field. Add the following code to custom_functions.php for activating the nosidebar custom field.
     function no_sidebars() 
    global $post;
    $no_sidebars = get_post_meta($post->ID, 'nosidebar', true);
    if ((is_single() || is_page()) && $no_sidebars)
        return false;
        return true;
    add_filter('thesis_show_sidebars', 'no_sidebars');

    The function no_sidebars in this code checks for the executing page and implication of the custom field. If the executing web page is either a page or a single post page which implements the custom field nosidebar, it will filter the sidebars to render the page without the sidebars.

  3. Use The Custom Field: After you have created and defined the custom field, you can flexibly use the custom field for any post or page — by simply selecting the custom field from the Custom Fields section.

Check out the ultimate guide to customizing the sidebars for customizing the sidebars for the Thesis theme for WordPress.

Posted In:

WordPress Support & Maintenance, Code Snippets, Thesis WordPress Theme Framework

Comment on Thesis Tip — Control Sidebars With Custom Fields In Thesis Theme For WordPress

Your email address will not be published. Required fields are marked *