How to stop showing menu in static home page wordpress - wordpress

Ok, I'm creating a wordpress theme. I don't want my navigation menu to show in the home page "Only" if the site admin setup Front page displays > A static page (select below).
otherwise I want to show the menu in home page & other pages too. I've used this <?php if(!is_front_page()):?> function, but it is not working.
some one suggest me <?php if(!is_home()):?>, but it is not working either.
So how do I make it work?

Please follow the below steps:
Dashborad > Settings > Reading
Select A static page (select below) option in Front page displays section.
Select the page you want to display from Front Page drop down box.
In header.php in the code for displaying menu, make the alteration as below.
if ( ! is_page( '{slug of the selected page in Front Page drop down box}' ) ) {
//enter your code to display menu here
}
?>

Related

Content written in the Page edit box not showing in the published page in Wordpress

I am not sure what I am missing. Please guide me and I apologize if my knowledge is too less.
I have a home template file i.e. template-home.php which actually contains nothing for now and is only containing the following lines ->
<?php
/**
* This is the front page code
* Template Name: HomePage
*/
get_header();
get_footer();
?>
I have created a page from wp admin and given the page title "Home" then I selected template "Homepage" for this page I have created from wp admin. Hence I have set the static front page to display "Home". Its perfectly showing the Home page as front page. But when I am giving any content in the edit box of the page "Home" from wp-admin and updating, those contents are not displaying in frontend. But if I put any content in the "Homepage" template , only then its getting displayed. I am giving an example what I tried below-
When I am giving the following in the page edit box then nothing is displayed in real.
[rev_slider_vc alias="homebanner" title="Home Slideshow"]
For your information the above is shortcode of revolution slider which is working perfectly , if I use it in any post. So the shortcode has no error for sure. Another thing whatever I write in the content box is actually not getting displayed in real.
Now the slider code, if I am putting directly into the Home template i.e. template-home.php then slider is getting displayed. The code is as follows ->
<?php
/**
* This is the front page code
* Template Name: HomePage
*/
get_header();
// Revolution Slider
putRevSlider('homebanner', 'homepage');
get_footer();
?>
Though my purpose is getting served well by putting code into the template file directly. But I want that the content I put in the edit box of the page from wp admin can get displayed in real. So what I need to do for that ?
Read https://codex.wordpress.org/The_Loop and https://developer.wordpress.org/reference/functions/the_content/
You need a loop and you need the_content to grab the content from the text editor.
A very basic example:
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
the_content();
//
} // end while
} // end if
?>
Work with that first with some plain text to test the loop.
Then add your shortcode for the slider [rev_slider_vc alias="homebanner" title="Home Slideshow"] in the text editor. And, look at the docs for the slider on how to place the function putRevSlider('homebanner', 'homepage'); directly in the page template file, if you want to do that rather than using the shortcode in the editor.
See https://codex.wordpress.org/Theme_Development for how WordPress themes are structured and the types of basic files you need in each theme, i.e. index.php, style.css, etc.

How to disable template files in single page wordpress theme

I am creating a single page Wordpress site and I would like disable/delete/remove all other pages so that they just return a 404.
So if the user tries to go to an archive page or a single post page it does not work. I only want one working page on the entire site.
You can simply force all pages to be redirected to the front page by putting the following code in your functions.php:
function redirect_to_homepage() {
if ( ! is_front_page() ) {
wp_redirect( home_url( '/' ), 302 );
exit;
}
}
add_action( 'template_redirect', 'redirect_to_homepage' );
Just a quick note: is_front_page() checks if the user is trying to access the page that is set for the front page in Settings > Reading. If no such page is set, use is_home() instead.
Reference:
http://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect
http://codex.wordpress.org/Function_Reference/is_front_page
http://codex.wordpress.org/Function_Reference/is_home
Instructions for what I think you want to have done. This will remove all other pages/posts, and make the page you did not delete into the home page of your website.
Log into your site
In the admin panel go to pages
Select all of the pages except the one you want to keep as the home
In the "Bulk Actions" select move to trash and click apply
Go into the trash section of pages
Select all of the pages
In the "Bulk Actions" select move to delete permanently and click apply
Repeat steps 2-7 for the "posts"
Go to the settings reading page in the admin panel
Check off static page
In the front page drop down select the page you did not delete
Click save at the bottom of the page.

Wordpress: create a custom home page

I want to create a website using wordpress, but I want my website to have a customized home page, created by me, completely different from the theme of the site, and then link the wordpress pages directly from my page.
Is this possible? How can I achieve this?
Can I simply create the page, and link the other created with the wordpress panel, without breaking everything?
According to official WordPress codex:
If a visitor goes to your home page at http://example.com/blog/, the following happens:
WordPress first determines whether it has a static front page. If a static front page has been set, then WordPress loads that page according to the page template hierarchy.
If a static front page has not been set, then WordPress looks for a template file called home.php and uses it to generate the requested page.
If home.php is missing, WordPress looks for a file called index.php in the active theme's directory, and uses that template to generate the page.
Therefore you just need to create a home.php template and place it with the other theme (which so ever theme you will use) templates and WordPress will automatically start using home.php template for the home page.
Just copy the default page.php template file and call it front-page.php. Change the configuration at the top of that file. Now create a new page called home.
Go to Administration > Settings > Reading panel and set a static front page.
For more help check this link on the Wordpress website:
https://codex.wordpress.org/Creating_a_Static_Front_Page
If you create HTML off your home page first than this is easy for you
First Create a file Like this "template-home.php" in your theme.
Now in "template-home.php" First you must write these lines at the top of the page
<?php
/* ==========
Template Name: Home
========== */
?>
After that add your header.php and footer.php like this:
<?php get_header(); ?>
// Your Content is here
<?php get_footer(); ?>
Now your Whole HTML is work between in Header and Footer
Then Go to your Admin Panel
Go to Pages > add new
and create a page named "Home"
NOTE: When you create a page Please Select a Template of Home and "Publish" it.
Then go to Settings > Reading and select "A static page (select below)" radio button, then a drop down is active and select your "Home" Page Then click on save changes.
I hope this will help you
You can create a front-page.php file in your active theme folder.
It can be use for both Your latest posts or a static page as you want.

How to differentiate Front page and other pages in Wordpress?

I have created a front page (i.e index.php) with my own design. This page will contain
header got from <?php get_header(); ?> [has navigation bar code]
Then some content. Here I'm showing three thumbnails of posts. [has slider, thumbnail posts etc]
And a footer from <?php get_footer(); ?>[has footer links]
The problem is, I see index.php loaded correctly as a front page. But when I navigate to other pages like About or Contact, the respective content from these pages is not showing up. Instead what getting loaded there is, same what Index page has. I don't want slider or thumbnail appearing on these pages.
So how to tell wp that, this is my front page, and this is my About page, don't load a slider and stuff on About page!?
use is_front_page() to determine the home page. like you only want slider on the home page then edit your header.php file that consist the slider part and do something like this
if( is_front_page() ):
// Front Page stuff like slider and
// whatever you want
endif;
Try this ,
if( is_home() || is_front_page() ){
//your home page content
}
else{
//other pages
}
For more here
Hope its works..
Make another template and set this template for your single pages. And then from backhand set it.
I usually create a front-page.php file, Wordpress will use that instead of index.php (which you can use as a generic template from then on).

Custom set "current-menu-item" class for specific pages in WP

I'm creating a custom WP theme and I'm using the Wordpress navigation bar. When switching between different pages, WP adds a "current-menu-item" class to link in navigation bar which corresponds to the current page.
However, if that page/post is not present in the nav bar, it doesn't add the "current-menu-item" to any of the nav bar items.
My problem is, when a user visits the page "BLOG" (which is actually a category page) and clicks on a certain post which opens the single.php template, I want the nav bar item "BLOG" to be underlined as it would if the visitor was visiting a blog page.
Sometimes I will want another nav bar item to be underlined when landing on SINGLE, depending on where the user came from (I also have homepage posts, then I'd like HOME to be underlined)
How do I accomplish this? Thanks.
You can use a filter and check what page you are currently on using conditional statements and add classes before the menu gets displayed:
function add_custom_classes($classes, $item){
if(is_single() && $item->title == 'BLOG'){
$classes[] = 'current-menu-item';
}
return $classes;
}
add_filter('nav_menu_css_class' , 'add_custom_classes' , 10 , 2);

Resources