Special Wordpress Tip ! How to Show Noshow Sidebars & Footers !
Hello all,
I have another technical topic for you, this one is a little bit special... :-)
But you will like it, I am sure...
I noticed that I am creating a niche for myself within the streams of blogs, some technical how to's and tips and tricks.
Personally, I think it suits me. :-)
Ok, here we go: Sometimes you wish that the sidebar or sidebars where not visible on that page. Or why does the footer is displayed on that page, it does not fit with the other content of the page. Also, the header can be removed from a page, but then you lose your navigation on that page and I do not recommend that. But it is possible.
This is the page before we add the code:
Sounds really difficult don't you think?
On that page the sidebar1 displays and sidebar2 doesn't, somewhere else both sidebars are gone and also the footer which makes it possible to only see the beautiful picture of the sky without distraction or you can read the blogs without all those special things at the sight...
How can we do this?
First we prepare our code by copy and paste these 2 lines in notepad:
<?php if ( is_page('Page 1') || is_page('Page 2') || is_page('Page 3') || is_page('Page 4')) : ?>
<?php endif; ?>
Then you have to change the page 1, page 2, page 3,... into the page names where you want that the sidebar will display. (see print screen below)
When you have the drop down menu's with extra entries also add those pages when you want that the sidebar is displayed on those pages.
See example:
<?php if ( is_page('About this Site') || is_page('How to buy a House') || is_page('Getting Started') || is_page('My best Choice')) : ?>
The second line stays as is, always!
<?php endif; ?>
The hardest part is already done, except when you have more pages, which will often be the case or when you have less pages...
Adding extra pages in the code line:
"|| is_page('Page 4')) " the part between brackets (it is also important that you copy the space between ) and " ) you copy and paste this as much as needed (how much extra pages do you have) just before the colon ":" ad the end of the line.
When you have done that just fill in the names of the pages that are left.
Of course, in every code there is almost always an exception and also here we have one.
When you want to include the frontpage and this seems to be a blog roll then the code for that page is different.
this is the code:" is_frontpage ", copy also the spaces that are between the brackets and paste it like this:
<?PHP if ( is_frontpage ) || is_page('How to buy a House') || is_page('Getting Started') || is_page('My best Choice')) : ?>
When the homepage is a static page, you can find the name in customizing your theme and you that name and you add it as a normal page.
Ok, now we have our code and from now it is easy-peasy... ;-)
First you go in your dashboard of WP to "Appearance" and then you select "Editor".
In the next screen on the right-side you select sidebar.php almost the lowest file you can find.
(or footer.php depending on which one you want to adapt, it can also be sidebar2.php but that you will know from the info of the theme.)
In the content screen you add the first line just under "*/ enter ?>" see print screen.
The second line you add at the end just under the line </div><!-- #secondary .widget-area. See print screen
Then you click on "update file" below the content screen... (see above)
And you check and even double-check the result: is everything how you want?
Please do this, a small typo is easily made.
Last thing to do: Please copy the 2 files in a document.
When something changes in the behavior (suddenly a sidebar displays where he does not have to display) or an update of the theme removed the 2 lines.
You can take your backup and restore everything as it was within 2 minutes!
This is the result after adaptation:
As the last remark, I want to add: I think this really something you should use when you need it, put it can not become the standard behavior on your website everywhere and always. So use it, but do it wisely.
When you have a problem with implementation or an extra question, don't hesitate to contact me or even better: just add a comment below!
Grtz,
Bert
Recent Comments
37
Great info again Bert! I'll try it out :)
I am really not in expert in codes though ... I never know where to put them. I tried several times to add codes in admin.php but I am not even sure that is the place to do that .
Informatica newbie lol but anyways worth a try :)
Thanks for sharing!
Angelique
Your very Welcome, Angelique!
To be honest admin.php I never have opened that one...
But when you need help for those things, you know where to find me...
Let me know if your test worked and my explanation is clear enough...
:-)
Grtz,
Bert
Hey, Bert. Nice bit of code you got there. Can you link me to your site where you have applied this so I can see what the page would look like with no sidebars :)
If I like it then I will copy the PHP code and put it in my files.
Yes, of course, but it is a test site where I applied this...
But still you can check it out of course!
I will pm you the site...
Grtz,
Bert
I just give it here, so maybe other people can check it also...
But it is a test site and everything can change in 3 days...
(But I will leave as is for 2 days at least.)
http://ignorant-test.siterubix.com/
Grtz,
Bert
Astounding work Bert I think in time I will tackle google code academy as I would love to be able to work our things like you.. thank you this is really useful
I think you are using reverse psychology on people and you seem to be getting a good response!
It's almost the same as having a supposedly 'Negative' Review on your website to make people want to read about it.
So when they read your Username, they are enticed to find out how ignorant you actually are, and to their surprise, you aren't even nearly!
Quite the opposite in fact!
Your gem is that you try to find out how to provide a solution, even if you don't know, that's far from ignorant!
Keep up the good work you do Bert!
You are a continuous inspiration to me!
Thank you Topachiever and your are spot on with the reason I love to use this Nickname...
Psychology is such an interesting matter, but I don't know as much about it than about the bits and the bytes...
My intention is definitely to continue as I started.
Thank for you great comment and you are as much an inspiration for me too!
Thanks, but I have to admit that TopAchiever is correct in his thought about my username... ;-)
And I use it since I was 16 so....
But maybe at one point it will be ignorant to keep Ignorant, who knows... :-)
Grtz,
Bert
Good Remark Chris, I did not mention the child theme implementation to keep everything as simple as possible. With these lines, the worse thing that can happen is that you don't see a sidebar or footer until it is fixed. And it is so easy that you don't need a child theme for this small change. (also child themes are mostly used for functions.php and style.css, of course, you can also add footer or sidebar, but that does not happen often.)
About the child theme, I really thought what the best solution was...
About the updates that are possible and that can maybe remove the 2 lines. I did not think about, but I will update my blog with asking to keep the lines they add in a file, so when suddenly the behavior is different or the lines or gone, they can easily re-implement the 2 lines in the correct PHP file from their backup file...
Thanks for your 2 remark!
Grtz,
Bert
Bert,
The information is going to be very helpful. I will try it tomorrow on one of my test sites. I just want to see what it looks like with my theme.
John
@Bert - since you like the nitty gritty and are quite analytical and pedantic, you have missed seeing that Chris is actually John!
Just thought I'd point that out to you! :-)))
Thanks, but it depends on which topic I guess... ;-)
Your Welcome and try it, it feels good when it works... :-)
See more comments
To me very technical but very interesting. Thank you. DAN
Thanks DAN