WordPress.org

Ready to get started?Download WordPress

Forums

remove class name from classes rendered by body_class() (13 posts)

  1. karthick-sk
    Member
    Posted 1 year ago #

    Am using 'admired' theme and have set one column for the whole site and am using pages for the site content. when the blog is viewed am not able to get the right sidebar even though the function get_sidebar() is present in the single.php and the content of the blog is filled for the whole width of the site. i need to show widgets on the right side.

    In body i have 'one-column' class which makes the blog content to fill for the width of the single column. So
    1. I need to switch to 'two-column' from 'one-column' class for the blogs and
    2. have the default r-sidebar shown in blog posts (make get_sidebar work in single.php)

  2. paulwpxp
    Font hero
    Posted 1 year ago #

    In this case, there is no need to remove classes returned from body_class().

    In fact, you need to add a class into it using the conditional check is_active_sidebar().

    Please see the real example in Twentytwelve ( actually most themes use this same method ), and take it from there.

  3. karthick-sk
    Member
    Posted 1 year ago #

    single single-post postid-1368 single-format-standard logged-in admin-bar custom-background one-column content customize-support instead of this if i have single single-post postid-1368 single-format-standard logged-in admin-bar custom-background two-column content customize-support my problem is solved related to blog content width.

  4. paulwpxp
    Font hero
    Posted 1 year ago #

    one-column is not a default body_class()output
    http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/post-template.php#L400

    This means that the theme you are using already has a function to filter the output of body_class()

  5. karthick-sk
    Member
    Posted 1 year ago #

    yeah, i have set one-column in admired theme setting for the whole site, i need to use two-column for blog posts alone, so is there a way to override the global theme setting and give two-column for blog posts, thanks for your effort...

  6. paulwpxp
    Font hero
    Posted 1 year ago #

    So the theme is this
    http://wordpress.org/extend/themes/admired

    The function to filter body_class() is this
    http://themes.trac.wordpress.org/browser/admired/1.2.1/functions.php#L239

    You can notice that the mechanism is there already but it uses page template check, if the default doesn't do what you want, you can extend (make changes to it) or roll your own entirely.

    First, make a child theme
    http://codex.wordpress.org/Child_Themes

    in your child's functions.php you have to remove that function from parent theme first and then make your own function that do the same thing with different conditional checks.

    To remove filter from parent is a bit tricky because the order of functions being loaded, so you need to hook it into a proper hook, in this case it's the after_setup_theme

    function my_remove_parents( $classes ) {
    	remove_filter( 'body_class', 'admired_body_classes' );
    }
    add_action( 'after_setup_theme', 'my_remove_parents' );

    Then just below that bit, repeat exact same thing as parent's, but with a function's name of your own, you can keep the same feature of the parent and just extend it by using OR (||) in the conditional check or make a whole new logic entirely.

  7. karthick-sk
    Member
    Posted 1 year ago #

    is there a way to check if its a page or blog, so i can alter the admired to use two-column in the lines you have mentioned above. can i use!is_page

  8. karthick-sk
    Member
    Posted 1 year ago #

    am new to the wp execution flow, can you suggest in which file i should add the hook add_action(),...

  9. paulwpxp
    Font hero
    Posted 1 year ago #

    There are lots of ways to check.
    http://codex.wordpress.org/Conditional_Tags

    When you say "blog", do you mean a single post page ? if so you are looking at is_single(), but if you mean a page that list posts by archive of any kind you are looking at is_archive(), if you mean the main blog home page, then it's is_home()

  10. karthick-sk
    Member
    Posted 1 year ago #

    thanks for providing all, i meant blog displaying page, that is is_single(). for this if there is no custom template for blog page, what shld be the argument passed. if i use

    if ( is_single() )
    its returning false.

    and in which file(.php) should the hook be added for adding the css class filter function to work.

  11. paulwpxp
    Font hero
    Posted 1 year ago #

    for this if there is no custom template for blog page, what shld be the argument passed. if i use if ( is_single() ) its returning false.

    You can combine the conditional checks with OR (||)

    in which file(.php) should the hook be added

    all the functions go to functions.php of your child theme.

  12. paulwpxp
    Font hero
    Posted 1 year ago #

    BTW, the title of this topic doesn't seem accurate, because you are using a theme that has other mechanism to manage how the sidebar will be loaded too.

    To get it work the way you want in the topic's description, you have to do other thing too, not just filtering the body_class()

    If you look into sidebar.php of your parent theme, at the very top you will notice the if check, that's where you have to apply the same logic used in child's body_class() filter.

    But it's best to keep 1 topic per 1 issue, so post the new one if needed.

  13. karthick-sk
    Member
    Posted 1 year ago #

    is_page_template ( 'tmp-threecolumn.php' ) in the if() condition prevents the sidebar from loading in sidebar.php. so will try to work on it with filter as you mentioned, then if not done will try posting new.

    thanks for the effort, will post the solution once i do and close it so others can get a idea from this.

Topic Closed

This topic has been closed to new replies.

About this Topic