• I’ve got a filter written to have the sidebars dropped when single posts display a certain category, so the content goes to 100% width. It works, except that it’s doing this to all single posts.

    Could someone help me with the correct category call-up? I thought I picked up the correct structure from some samples of people using categories in filters, but I must be overlooking or missing something.

    Thsnks!

    add_filter('single_template', 'product_posts_no_sidebar');
    
    function product_posts_no_sidebar() {
    if ( in_category('store-all') )
     ?>
     <style>
     #secondary { display: none; }
     .site-content  { width:100% !important; }
     </style>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter David Borrink

    (@davidborrink)

    Okay, I tried an if (is_single() && in_category('store--all')) condition and I still get the same result.

    add_filter('single_template', 'product_posts_no_sidebar');
    
    function product_posts_no_sidebar() {
    if ( is_single() && in_category('store-all') )
     ?>
     <style>
     #secondary { display: none; }
     .site-content  { width:100% !important; }
     </style>
     <?php }

    And so I pulled that condition out and ran this:

    add_filter('single_template', 'product_posts_no_sidebar');
    
    function product_posts_no_sidebar() {
     ?>
     <style>
     #secondary { display: none; }
     .site-content  { width:100% !important; }
     </style>
     <?php }

    Same result, so obviously my use of ‘single_template’ works as a default so that no matter what I put in, my sidebars disappear on all single pages and the content goes to 100%.

    How do I get single pages to respond only to the categories I specify?

    Thread Starter David Borrink

    (@davidborrink)

    In reading the different filter tags, I’m wondering if someone could rewrite the explanations a little clearer and perhaps with examples.

    For those who are newer, it might help them more.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trying to drop sidebars from specific single post categories’ is closed to new replies.