PHP – WordPress – Disable Sidebars, Widgets on Page Template

The following php example helps you disable (remove) some sidebars, or widgets at all in WordPress
on page template with suffix in the template name (*-no-widgets.php, *-no-sidebars.php)p.

Code Example:

<?php
 
/* Disables widget areas. */
add_filter( 'sidebars_widgets', 'remove_sidebars' );
 
function remove_sidebars( $sidebars_widgets ) {
  global $wp_query;
   
  if(is_singular()){
	  $template = get_post_meta( $wp_query->post->ID, "_wp_{$wp_query->post->post_type}_template", true );
   
  // Disables all widgets
  if(preg_match("/(-no-widgets.php)$/i", $template))
  	$sidebars_widgets = array( true );
   
  // Disables 'primary' & 'secondary' sidebars widgets
  	if(preg_match("/(-no-sidebars.php)$/i", $template))
  		$sidebars_widgets['primary'] = false;
  	$sidebars_widgets['secondary'] = false;
  }
   
  return $sidebars_widgets;
}
 
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

8 Comments

  1. avatarfree youtube views exchange

    I do not even know how I ended up here, but I thought this post was
    great. I don’t know who you are but certainly you’re going to a famous blogger if you are
    not already 😉 Cheers!

  2. avatarFree Live Sex Cams

    Excellent, what a web site it is! This web site presents useful
    information to us, keep it up.

  3. avatarAleisha

    Hello, after reading this amazing piece of writing i am
    too cheerful to share my knowledge here with friends.

  4. avatarsand bunker}http://golfparkspoland.pl/

    Km nie powinno stanowić dla niej dużego problemu.

  5. avatarv neck christmas sweater

    My spouse and I stumbled over here coming from a different page and thought I should check things out.
    I like what I see so now i am following you. Look forward to looking into your web page yet
    again.

  6. avatart shirt heat press

    I’m amazed, I have to admit. Rarely do I come across a blog that’s both equally educative and entertaining,
    and without a doubt, you have hit the nail on the head.
    The issue is something which not enough people are speaking intelligently about.
    I’m very happy I found this during my hunt for something relating to this.

  7. avatarugly christmas sweater run

    Its like you read my mind! You appear to know so much about this,
    like you wrote the book in it or something. I think that you can do with some pics to drive the message home a bit, but
    other than that, this is wonderful blog. A great read.

    I’ll definitely be back.

  8. avatarlink bokep

    Kulitnya putih bersih, dengan betis yang woow, berambut menantang pastilah perempuan menawan ini punya nafsu seksual yang liar, itu kata temanku yang pengalaman seksnya tinggi Buah dadanya kelihatan menyembul dari balik gaun tidur itu, apalagi
    dikala dia melangkah di sampingku, samar-samar dari sudut
    mataku nampak cantik payudaranya yang putih lembut

    “Uh , apa ini gara-gara film itu?”, batinku lagi

    Daya bos aon338 mulai kurang didik, atau selama ini saya memandang
    cs senantiasa menerapkan kutang seksi dan berhijab jadi saya tak tahu wujud tubuhnya yang sebetulnya, segera saya memasukkan bayang-bayang ke dalam
    adegan film tadi

    “Hmm ”, tidak sadar mulutku mengeluarkan bunyi itu
    “Ada apa, Di?”, isteri bos aon338 itu memandangku dengan alis berkerut

    “Eh , kau ngelamun yah, ngelamunin siapa sih? cs yang seksi?”, tanyanya
    memperhatikan cs seksi dada bos dan leader aon338 berdesir
    sesaat pandangan mataku tertuju pada belahan dadanya

Leave a Comment

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