I am trying to hide the header on a specific page in WordPress. I know that I can do this using CSS.
The page id as displayed in the dashboard is:
wp-admin/post.php?post=31221&action=edit
The page has a header without an id or class (not sure who built it). But I can hide the header with:
header {display: none;}
I can't seem to hide the header on the specific page. I have tried:
.page-id-31221 header {display:none;}
.pageid-31221 header {display:none;}
I have also tried the same with # and postid etc etc. Is there another way to hide the header on that page?
Failing that is there a way I can hide the header after it has been called in the template? I have created a custom template for the page but im not sure of the php to use to hide it. If I remove <?php get_header();?> from the template then the whole page disapears.
The website is here: Website
You say you have created a template for this specific page.
In which case you can use jQuery to hide the header. Add this to the end (or start) of your page template.
<script>jQuery('header').hide();</script>
You would probably want to wrap this inside something like a jQuery( document ).ready(function() { to ensure the page is loaded before the script is run. Maybe add in the defer attribute too.
You can modify your header.php by adding an IF-statement which checks for the required pages by either the page/post ID or title.
Page/Post ID method:
if(is_page(get_the_ID()) != YOUR_PAGE_ID) { // show header }
Page/Post Title method:
if(!is_page(get_the_ID('PAGE_POST_TITLE'))) { // show header }
Either of these methods should work. *Not tested.
You can do this by checking the page name.
if( is_page( array( 'about-us', 'contact', 'management' ) ){ #hide your header; }
If you want more details please read the wordpress official documentation. It will helpful for you.
Read wordpress official documentation
This works for me. A simple trick:
Check your style class name in your header.php in the top example: class="header">
And place this code in the top from your php template or page.
<head>
<style>
.header { display: none; }
</style>
</head>
<body>
Related
I was given the task of customizing a specific section of a website. This section is primarily made by an Event Manager Plugin on WordPress. This plugin allows users to create their own events that will be published in a calendar page. The thing is, I need to get rid of the page header only on the pages created by this plugin, that will have an URL similar to this: http://mypage.com/eventos/user-event-name
So, I only need to apply the code .site-header { display: none; } ONLY to the pages that have this /eventos/something URL. Can this be done?
When I put the above code on the Custom CSS of my theme it gets rid of the header across the whole website, and I don't want that.
I have absolutely no background in CSS so I most definitely am using the wrong definitions here. Thanks in advance, hope someone can help me!
You can check if there is evestos in URL and add a class to body
like this
add_filter( 'body_class','my_body_classes' );
function my_body_classes( $classes ) {
$url = strpos($_SERVER['REQUEST_URI'];
if($url, "/eventos/")) {
$classes[] = 'eventos-page';
return $classes;
}
}
After that you can add css to that class like for example
.eventos-page .site-header {
display: none;
}
In my Wordpress Theme, I have a "default" footer I use for every page, but I created a new footer I want to display only on the home page.
How do I hide the old footer and display my new footer on the home page?
There are a number of ways you could solve this, and none are more or less correct than the others. The way I would suggest is this;
Assuming you don't have it already, create front-page.php template and copy the content of page.php into it (if that's the template you're using).
Replace get_footer() at the end of front-page.php with get_footer('home') (assuming your new footer is called 'home-footer.php' (see the docs for more on that one)
As an alternatively, you could simply edit page.php and replace get_footer() with something like:
if(is_front_page()) { //check if current page is the home page
get_footer('home');
} else {
get_footer();
}
Which utilises the is_front_page conditional. (see conditional tags)
Open the header.php
Edit the <body> tag and make it <body <?php body_class(); ?>>
now in your homepage your body tag will render <body class="home">
then write css like:
body.home footer {
display: none;
}
add new footer in your homepage content
You can create custom template for homepage and call the new footer from that template using the function get_footer( $name ), here $name is the name of the new footer that you have created. Then select the homepage template from dashboard home page.
So, I have this PHP function that adds the X-UA-Compatible meta tag to the head of every page of my Wordpress site. (I'm new to Wordpress and PHP so forgive me about terminology). It's in the functions.php file of my StudioPress child theme.
The problem is the tag only works if it's placed very near the top, and the way I have it set up now causes the tag to appear halfway down, so it doesn't work. How can I force this tag to appear at the top of the head of each page?
Ex : You can use wp_head action. The wp_head action hook is triggered within the <head></head> section of the user's template by the wp_head() function. Although this is theme-dependent, it is one of the most essential theme hooks, so it is widely supported.
function aaa_custom_function() {
?>
Your Tag
<?php
}
add_action('wp_head', 'aaa_custom_function', 1000);
Use the third parameter to control the position. Change 1000 to another values to find the perfect position.
Create your custom hook like this way.
open header.php then write this below line where you want to show meta tag
<?php do_action("my_custom_metatags");?>
Now open your functions.php and write down this below code
function my_custom_metatags_fn()
{
//your tag goes here.
}
add_action("my_custom_metatags","my_custom_metatags_fn");
//Test this code it will work like a charm for you.
adding to #Damith answer wp_head action will work.
Refrence
also you can override header.php file into your child theme.
add this code in function.php
<?php function your_custom_function() {
// your custom code which you want to add in header file
}
add_action('wp_head', 'your_custom_function', 1);
I have developed my own custom theme for WordPress. Now recently I installed my theme under WordPress 3.9.1 and I have noticed a rather annoying message which appears on the second and third pages of my site. The message appears in the footer area. It does however not appear on the home page. The message conveyed is as following:
site name proudly powered by Wordpress Entries(RSS) and Comments(RSS)
Now one solution I have seen is to put the following into the style.css. however it does not work.
#site-generator{
display:none;
}
The second solution is to modify the footer.php file and remove a block of php code, now interestingly enough my theme does not contain a footer.php file. Just wondering is it some WordPress system file pushing out the message on my theme.
Any help greatly appreciated.
If you call get_footer() anywhere in your theme, but your theme doesn't include a footer.php, then a footer template is provided for you automatically:
If the theme contains no footer.php file then the footer from the default theme wp-includes/theme-compat/footer.php will be included.
This "theme compatibility" footer outputs a standard footer which includes the lines:
<?php printf(__('%1$s is proudly powered by %2$s'), get_bloginfo('name'),
'WordPress'); ?>
<br /><?php printf(__('%1$s and %2$s.'), '' . __('Entries (RSS)') . '', '' . __('Comments (RSS)') . ''); ?>
Which I'm pretty sure is where your "site name proudly powered by Wordpress Entries(RSS) and Comments(RSS)" will be coming from.
So, check your theme files for "get_footer()". If you don't have a footer.php, then you probably don't want to be using that.
However, it would be normal to include a footer.php so you can have standard footer code across all pages, for doing vital things like calling wp_footer() on every page, which is something you must do in a theme.
wp_footer is a standard hook point for plugins, themes, and WordPress itself to inject scripts, and anything else necessary, just before the closing of the HTML body, </body>. It's how the admin menubar gets output, for example, and often plugin Javascript. So you absolutely want it called at the bottom of every template, and providing a footer.php that does this (and closes your <body> and <html> tags, etc.) and including it from all of your template pages with get_footer() is the normal way.
If your current code works well and produces valid HTML while using the standard "compatibility" get_footer(), then personally, I'd add the bare minimum footer.php to your own theme:
<?php wp_footer(); ?>
</body>
</html>
Your CSS should probably say something more along the lines of
.site-generator {
display: none;
}
or if that doesn't work you could always do
.site-generator {
display: none!important;
}
What you have is missing the '.' which refers to the class 'site-generator'. It might also be an ID, in which case, it should look like
#site-generator {
display: none;
}
If you'd rather remove it from the theme, you could let me know what theme you're using, and I can take a look at where it is occurring in the theme.
I know this can be done only by making some changes on the file footer.php.If you can't find the footer.php file, look for another PHP file with "foot" or "footer" in the filename.
Just see a detailed explanation here.
If you're not using a footer.php file, the footer info must be in the bottom of index.php and page.php. My hunch is that the generator was removed from your page file, but not the index file. I would check that file and make sure the code isn't there.
If that doesn't work, you need to see what the css selector is surrounding the generator. If you right click on the sentence within your browser, you should get some sort of 'inspect element' option. (I use Chrome, but other browsers have similar tools.) Inspect the element and you should see some sort of class or id to target. It may be a
<div id="example">
or
<p class="example">
Find the id or class and modify your css, i.e.:
for an id:
#example {
display: none;
}
or for a class:
.example {
display: none;
}
If the generator is being added by an external source you may need to add !important.
.example {
display: none!important;
}
Good luck!
Another route would be copy the footer.php file in your theme's directory and paste it into a child theme. Open up the footer.php file in your child theme and delete the text with the sitename and powered by. It should be wrapped in php tags.
Easy! If your theme doesn't have a footer.php file (for example if you are creating a theme from scratch), create it and leave it empty. It will just disapear the annoying "proudly powered by..."
Example of theme/:
style.css // theme info
header.php // empty file <----
footer.php // empty file <----
index.php // file with wordpress loop, etc.
you can edit your theme in admin panel, (footer.php)
if you see an error on your homepage when you edit the footer.php you can use javascript to delete that. But first you should add tag with an id, then access that id in javascript like;
function myFunc(){
document.getElementById('id').innerHTML ="";
}
then edit your body tag like
<body onload="myFunc()">
I want to display certain text in all my posts except if it's in this one category. How do I do that? Oh yea I almost forgot I want to include the title of the post in the text. So I think I need to use echo, cat='-5', and or something?? I don't know how to form it though. Thanks!
You could use the Wordpress function in_category(). When you use it inside the loop, it returns true if the current post is a member of the category you passed it.
<?php
if ( in_category('my-category'))
{
// don't output text
} else {
// do output text
}
?>
Do you require the text to be completely locked away, or just hidden from view? If you only need it hidden from view (but accessible to anyone who chooses to pry) then you may be able to do it very quickly using css.
If you have coded your theme - or are using someone else's - that adds helpful styles into the header, you may have a lot to work with already. For example, this is a body declaration generated by the Thematic theme:
<body class="wordpress y2011 m01 d31 h12 archive category category-orthopaedics">
Say you have a chunk of content to hide:
<div class="text_to_hide">This is what gets hidden.</div>
Then you declare the CSS as:
.category-orthopaedics .text_to_hide { display: none; }