Display/hide widget on specific pages in Blogger
When you add a widget (or a gadget as Blogger would call it) to your blog, by default the widget would appear on all pages –homepage, index, archive, post and static pages. But what if you want a certain widget to appear only on a certain page or pages, can it be done? In other words can you select on which page/pages the widget would or would not appear? The answer is yes you can -by using Blogger conditional tags.
Note: This trick doesn't work with Labels, Archive and Followers gadgets. For these gadgets you want to use the CSS's display none method.
Let us proceed,
1. Find your widget or section Id
To address a widget or a section in HTML, you need to know its Id. Here’s how to find a widget or section Id.
2. Locate the widget code in HTML
- Go to Dashboard > Design > Edit HTML.
- Check the Expand Widget Templates check box on top right of the HTML window.
-
Find your widget in the HTML by using Ctrl+F and entering the widget Id in the search box.
Your widget code might look like this. It may be a little different, but it’s okay. Just pay attention to the highlighted lines. Widget content is contained in between those two lines -in "includable" section.
<b:widget id='WidgetID' locked='false' title='Widget title' type='HTML'> <b:includable id='main'> <b:if cond='data:title != ""'> <h2 class='title'><data:title/></h2> </b:if> <div class='widget-content'> <data:content/> </div> <b:include name='quickedit'/> </b:includable> </b:widget>
3. Choose the appropriate conditional tag
I listed some conditional tags in another post -Targeting specific pages with conditional tag. Copy your desired tag from there and apply it here.
4. Apply the tag
Paste the tag (from step 3)
immediately after <b:includable id='main'>
and the code line 11 to 15 immediately before </b:includable>
, as shown below.
<b:widget id='WidgetID' locked='false' title='Widget title' type='HTML'> <b:includable id='main'> PUT CONDITIONAL TAG HERE <b:if cond='data:title != ""'> <h2 class='title'><data:title/></h2> </b:if> <div class='widget-content'> <data:content/> </div> <b:include name='quickedit'/> <b:else/> <style type='text/css'> #WidgetID {display:none;}/*to hide empty widget box*/ </style> </b:if> </b:includable> </b:widget>
Replace WidgetID
in line 13 with the widget ID from code line 1.
The code will check whether the condition is true or false:
- If the result is true, it executes (and display) the widget’s content.
- If the result is false, it skips the content and hide the widget.
You need to hide the widget because in most templates the content-less widget will still appear -as an empty box.
5. Save and view
Click Save Template button and view your blog.
That’s all to it. Enjoy!
Update Nov 2010
Revised code to prevent empty widget box from appearing on other pages.
88 comments to "Display/hide widget on specific pages in Blogger"
wei, xreti la. haha
http://fitridzulkifli.blogspot.com
@fitri oh fitri
Ape yang tak reti nyer?
Very nice tip! I actually figured it out myself, but I didn't know the constants for static pages & other.
But isn't the condition for b and d the same?
@gxg
Hey thanks for pointing that out. I corrected it.
I bookmarked your blog.Nice.some of them are really rubbish.beating about the bush.you made it simple thanks
wow, many thanks very useful post!
@ryansael
Welcome, do enjoy you visit and subscribe to stay updated.
Hi
Every thing you do you do it perfect. Thanks
@عرفان خیراندیش (حرف حساب)
You're welcome
I hope that the writer is reading this. I need to have my ads show only on static pages and post pages. I can't seem to get it working, please help!
@Korin
Use this:
[b:if cond='data:blog.pageType == "item"']
WIDGET CONTENT HERE
[b:else/]
[b:if cond='data:blog.pageType == "static_page"']
WIDGET CONTENT HERE
[b:else/]
[/b:if]
[/b:if]
WIDGET CONTENT is the codes from line 4 to 9 in step 3.
Hey there!
I'm was hoping to be able to add the Blogger Labels widget and the Archives widget to a static page (preferably with no other widgets on it but those two), but it will not allow me to do so. I tried the followers widget with the same outcome. Does it have to be an HTML widget, or can this code work for other widgets?
Dani
@[Dani]
Apparently this hack doesn't work with Labels, Archive and Followers widgets.
Maybe you want to try another method.
WAHH!!! tq2!! @Greenlava..leh x tgk2 kan blog aq nh..www.cracksevens.co.cc
aq nak centerkan header aq tuh..camne ek?
@Cracksevens
Go to Design > Template Designer > Advanced > Add CSS and add this:
.header-inner img {margin: 0 auto !important;}
.header-inner {text-align:center !important;}
THANK YOUUUUUUUU!!!!!
sori greenlava..out topic skit..aq nye blog bile g kat post mane2..xkuar title post tu kat title bar tu..camne ek?
@Cracksevens
Nampak elok jer
hah..sori..aq tukar template tros..
how do you remove the squares where the widget used to be? it gets hidden ok but there is a rectangle or square where it would normally appear?
Man Imba dude.
I am u r fan man whoever wrote this blog.
It worked
Thanks Thanks Thanks
http://zeehunter.blogspot.com
@Zeehunter
A true fan subscribes, follows, retweets and shares :)
I have made style changes to the static pages. Now I want the .main on each of the static pages to be different. I put .main as clear in the static page html. Now how do I change the .main on each page?
@Charlotte
To apply styles to individual static pages, you just need to add a style tag on top of each page content. You do this in post editor HTML mode, like this:
[style]
.main {CSS PROPERTIES IN HERE}
[/style]
YOUR STATIC PAGE CONTENT HERE
Hi,
I have used this code and it has worked really well. The only problem i have came across is that there is an emtpy box appearing at the top of my other pages as well. Do you know why this happens. Is there a way to get rid of it.
You can have a look at : www.emoviesedinburgh.blogspot.com to see what i mean.
Thank
Ricky
@Welcome
Try putting this code after [body]
[style]
#"BlogList1 {display:none;}
[/style]
a very cool post... very useful!
you are amazing!
Hi Greenlava,
boleh tolong tak macamana nak HIDE OutBrain Star Rating widget dari page navigation result? pada main page ok tapi bila klik kat page 2 atau next OutBrain Star Rating widget ni keluar lak. saya nak widget ni pada post je
So I'm trying to only include this on my individual article pages that are reached when a reader clicks on an article title. I figured the way I would do this is by using "if=main page than do nothing else do something" logic. But I'm running into problems. This worked, for a single article:
[b:widget id='HTML2' locked='false' title='Floating Social Media Buttons' type='HTML']
[b:includable id='main']
[b:if cond='data:blog.url == "http://engineeredtothemax.blogspot.com/"']
BLAH for don't show
[b:else/]
BLAH for show
[/b:if]
[/b:includable]
[/b:widget]
I then tried to add an or statement to the if clause, and it generated a test page, but when I went to the actual page, it didn't show up anywhere:
[b:if cond='data:blog.url == "http://engineeredtothemax.blogspot.com/"||"http://engineeredtothemax.blogspot.com/p/engineered-denver-sports.html"']
BLAH for don't show
[b:else/]
BLAH for show
[/b:if]
[/b:includable]
[/b:widget]
Then I decided to try the if, elseif, else tree to include another page that I'd be hidden on, but that ended the same way as the or statement:
[b:if cond='data:blog.url == "http://engineeredtothemax.blogspot.com/"']
BLAH for don't show
[b:elseif cond='data:blog.url == "http://engineeredtothemax.blogspot.com/p/engineered-denver-sports.html"']
BLAH for don't show
[b:else/]
BLAH for show
[/b:elseif]
[/b:if]
[/b:includable]
[/b:widget]
Any suggestions, even though this isn't truly related to this article?
What is related, is that I get a white box across the center of my page. How do I get rid of that?
@Riz2011
Rasanya awak sekarang menggunakan condition ini:
[b:if cond='data:blog.url != data:blog.homepageUrl']
sila gantikan dengan yang ini:
[b:if cond='data:blog.pageType == "item"']
@Engineered to the MAX
1. To fix the floating button widget width, remove this:
[center][p style="font-family: tahoma,arial; font-size: 12px; width: 55px; margin: 0pt;">Share the brilliance[/p][/center]
2. I guess what you want to do is display the widget only on post pages.
If that's the case, try this:
[b:includable id='main']
[b:if cond='data:blog.pageType == "item"']
BLAH for show
[/b:if]
[/b:includable]
I have a labels page and I want the labels to show up only in the labels page, how do I hide it from the rest of my pages.
[b:widget id='Label1' locked='false' title='Labels' type='Label']
[b:includable id='main']
[b:if cond='data:title']
[h2]
[/b:widget]
http://www.quicktattletails.com/p/labels.html
Any help would be very much appreciated!
@lighttraveler
[b:widget id='Label1' locked='false' title='Labels' type='Label']
[b:includable id='main']
[b:if cond='data:blog.url == "http://www.quicktattletails.com/p/labels.html"']
.
.
[/b:if]
[/b:includable]
[/b:widget]
It didn't work, any other suggestions?
@lighttraveler
It should work, if you entered the code correctly that is.
Why don't you post the code on my Facebook page.
starting from [b:widget id='Label1' locked='false' title='Labels' type='Label']
until
[/b:widget]
I'll add the conditional and repost there.
hi
is there a way to hide an image in a post from "post page" but NOT from "main page" ?
thank you
@Art Attack
First, give the image an ID.
Then conditionally hide the image (ID) using CSS's display none method tutorial. In your case replace the static page conditional with post page conditional.
was it possible to show followers widget on homepage only?? Everytime i tried to add [b:if cond='data:blog.url == data:blog.homepageUrl'] it'll return to normal again like haven't been edited before...
@Noname
For Followers widget use CSS's display none method.
This worked well for me thank you Greenlava.
I realized that I not only want the hidden widget to show up on home page, but on the individual post pages. I only want to hide them on static pages.
How to do this? Can I change he conditional code to say "hid widget on static pages (only) instead of show it on the home page?
I figured it out! Change == to != and change the homepage.URL to "static_page".
@Harvey44
Use static page conditional + "not equal" operator:
[b:if cond='data:blog.pageType != "static_page"']
it will show the widget only on pages other than static pages.
I am very new to this but I am trying to remove my sidebars from all stand alone and post pages. I have tried other methods of removing the sidebar, they didn't work for me. Therefore I am attempting to try this, but I am having one problem, I don't know exactly where to put conditional tags. This is because my coding seems to be slightly different
(Below is an example)
(/div>
(div id='backlinks-container'>
(div expr:id='data:widget.instanceId + "_backlinks-container"'>
(/div>
(/div>
(/div>
(h2 class='title'>
Please help, if I need to provide any other information please let me know.
@Custo-Minz
Follow this tutorial:
Apply different layout/styling to static pages
to hide the sidebars on static pages.
And to hide them on post pages, repeat the same steps but this time use this conditional tag:
[b:if cond='data:blog.pageType == "item"']
thanks a lot
This post is understandeable but, what if I want to put a picture on a certain page. Does this illustration work for me.
@kamaunyrroh
This method should work on anything, as long as it lies in a widget (except Label, Archives and Followers of course).
Hi Greenlava,
What I'm trying to do is (I think) a mix of what you refer to in your answers 31 and 44. I want the floating bar on posts (with individual statistics for each post) but I don’t want it to appear on my static or landing pages. Can you help?
MS
@Marc Snyder
I think answer 31 alone is enough to achieve what you've described. Have you tried it?
Hello,
I cannot figure out why hiding the empty box it is not working (the rest works, the widget is only on the homepage, but the other pages have a space left behind):
[b:widget id='Text1' locked='false' title='' type='Text']
[b:includable id='main']
[b:if cond='data:blog.url == data:blog.homepageUrl']
[!-- only display title if it's non-empty --]
[b:if cond='data:title != ""']
[h2 class='title'][data:title/][/h2]
[/b:if]
[div class='widget-content']
[data:content/]
[/div]
[b:include name='quickedit'/]
[b:else/]
[style type='text/css']
#Text1 {display:none;} /*to hide empty widget box*/
[/style]
[/b:if]
[/b:includable]
[/b:widget]
Many thanks!
@Anonymous
The code looks perfect to me.
Maybe the space is something else.
This is great because it will allow my blog to be more interactive.
same as post #25: "I have used this code and it has worked really well. The only problem i have came across is that there is an emtpy box appearing at the top of my other pages as well."
your response:
Try putting this code after [body]
[style]
#"BlogList1 {display:none;}
[/style]
where's [body] ?
:)
@Anonymous
That was before the code update in Nov 2010.
The current code hides the empty box in Step 4 code line 12~1).
Thank you Greenlava but I still have the empty widget (or marge) into all others pages than the home page. but maybe I have too much widgets (27).
If you have a time to look at my blog: http://moto-links.blogspot.com/
Thank you again
@Anonymous
Replace "WidgetID" (in #WidgetID) with your own widget ID.
I am trying to hide one widget in a static page but it is not working at all. The code in the if and else section is being displayed in all the pages.
Could you help?
[b:widget id='html9' locked='false' type='html']
[b:includable id='main']
[b:if cond='data:blog.url == "http://90mn90d-en.blogspot.com/p/quienes-somos.html"']
[p]DONAR QUIENES[/p]
[b:else]
[iframe width="250" height="199" src="http://www.youtube.com/embed/STryg59skt8" frameborder="0" allowfullscreen][/iframe]
[p]DONAR[/p]
[/b:else]
[/b:if]
[/b:includable]
[/b:widget]
tak ada contoh ke? saya nak tahu apa hasilnya tutorial ni...
@Jose
So you want to hide the video from that static page...try this:
[b:widget id='html9' locked='false' type='html']
[b:includable id='main']
[b:if cond='data:blog.url == "http://90mn90d-en.blogspot.com/p/quienes-somos.html"']
[p]DONAR QUIENES[/p]
[b:else/]
[iframe width="250" height="199" src="http://www.youtube.com/embed/STryg59skt8" frameborder="0" allowfullscreen="true"][/iframe]
[p]DONAR[/p]
[/b:if]
[/b:includable]
[/b:widget]
@Nukeufo89's Blog
Contoh ada dalam blog ni.
Tengok widget Recent Posts di sidebar. Cuba awak pergi ke homepage, widget ni takde kat sana sebab saya dah apply trick ni (untuk buat widget ni keluar dalam post pages sahaja).
I want to block slider on certain pages. Its code is in template. Can you help me to figure it out for Indian-Share-Tips.Com
Regards
@Analyst
This tutorial is not applicable to your slider because it isn't a widget (as the slider is hard-coded into the template HTML).
You want to follow another tutorial: Targeting specific pages/URLs with conditional tags
how to display widget only in special label? e.g. i have a label "facebook" and i want "this widget" display only in posting page label "facebook". how to? thanks!
I'm not sure if you've answered this before, but how do you put archives on a static page (and then remove it from the other pages? Thanks!
@Kelly
1. Create a page and get the URL.
2. Apply this conditional to the Archive widget:
[b:if cond='data:blog.url == "PUT_URL_HERE"']
thank you for this guide.
Hello,
Is there a way to apply a conditional tag to a conditional tag?
I added this Read Only code to my site to compress the posts. I added the condition to not compress the post if it is the first post on the page, but I want to make it so the "First Post" condition is applied to ONLY the homepage, so that on the Labels and Archives pages ALL of the posts are compressed. Is that possible?
Thanks so much!!!
The tip for hiding the widget (step 4) is GREAAAAAAAAAAAAAAT !!!
Thanks a lot !!! (and hello from France ;-))
@Curtain Up Cookie Design
Sure that's possible. Here it is:
[b:if cond='data:blog.url == data:blog.homepageUrl']
[b:if cond='data:post.isFirstPost']
PUT READ ONLY CODE HERE
[/b:if]
[/b:if]
Hot to Hide Widget Item page only using conditional tag, not css.
<b:if cond='data:blog.url == "/p/privacy-policy.html"'>
<style type='text/css'>.post-header, #comments, #PopularPosts1, #HTML7, #BlogArchive1, #HTML10 {display:none}</style>
</b:if>
<b:if cond='data:blog.url == "/p/contact-form.html"'>
<style type='text/css'>.post-header, #comments, #PopularPosts1, #HTML7, #BlogArchive1, #HTML10 {display:none}</style>
</b:if>
<b:if cond='data:blog.url == "/p/disclaimer.html"'>
<style type='text/css'>.post-header, #comments, #PopularPosts1, #HTML7, #BlogArchive1, #HTML10 {display:none}</style>
</b:if>
Have you any idea to minify this code.. please help me..
@Bikky
Not much can be done to minify it.
However, there is better way of applying CSS to individual page. I wrote about it here in section III: Apply different layout/styling to static pages.
Thank you very much for sharing this useful blogging tips, if anyone want to get listed on my blog directory please visit my blog
Hi,
great site with a lot of help.
I'm already successfull in hiding the sidebar etc. on a static page. But now I like to hide the same on one label site (not on all !)
Is that possible ?
My blog: http://lazyharrytest.blogspot.de
and the site: http://lazyharrytest.blogspot.de/search/label/Maps
Hey Greenlava,
another issue: so I want my twitter feed to appear only on this page:
http://tfi-alumni-impact.blogspot.in/p/mouthpiece.html
My code looks like this:-
<b:widget id='HTML4' locked='false' title='Twitter' type='HTML'>
<b:includable id='main'>
<b:if cond='data:blog.url == "http://tfi-alumni-impact.blogspot.in/p/mouthpiece.html"'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>
<b:include name='quickedit'/>
<b:else/>
<style type='text/css'>
#HTML4 {display:none;}/*to hide empty widget box*/
</style>
</b:if>
</b:includable>
</b:widget>
As you saw on the page, the twitter feed isn't appearing on ANY page :(
What went wrong?
Thanks again and sorry for all the trouble!
@Harald
Yes that's possible. Use this conditional tag:
<b:if cond='data:blog.url == "http://lazyharrytest.blogspot.de/search/label/Maps"'>
Thx,
I've tried that, but it doesn't work. Then I tried ist with blogspot.com instead of blogspot.de, and to my surprise it worked,although the blog has a .de ending, dont't understand that.
It works for me! You have awesome articles on Blogger.
@Ananyaa Ravi
Try replacing the .in country domain with .com like Harald did in comment #78.
I just want to say thank you. Finally after many hours trying different things I found your site and my blog from blogger is now having widgets only on home page. Thank you so much.
you are simply Awesome! Thanks for your great posts
Very nice and useful tips for all bloggers who want to hide a widget in specific page. Thank you for sharing
thanks mate, ive already hide one of my widget on my homepage.
Great!!! Thank you so much! You're awesome! Others still miss your 11-15 command.
thanks helped
Its amazing man...Truly deserves my comment..
You made everything simple..:)
Concise and helpful. Thanks!
Post a Comment
We love to hear from you! Leave us a comment.
To ensure proper display, HTML/XML/Javascript need to be escaped first using this escape tool.