I have a slider that displays only on our homepage with the following condition
<?php if( is_home() ) : ?>
It works properly with one exception, external pages located outside of the sites main folder that call the header display the slider as well.
Is there a way to designate a page as "not home/front"?
<?php is_front_page(); ?>
change is_home() to that and it should fix it right up.
Related
I've this code in the header Homepage that find automatically the title page for homepage and the posts how title tag. But I've my personal title tag only in the home page. The source code show 2 title tag in the home.
How can I hide this code in the home?
<? php wp_head(); ? >
i think, you can use the "is_home()" and "is_frontpage()" function, depending on how your frontpage is setted up in theme (static page, blog page...), one of them or using logical and can be necessary.
with this you can do like:
<?php
if( !is_home() && !is_frontpage() ) {
wp_head();
} else {
// custom head code
}
?>
an other way is using a separate template for home/frontpage (using a frontpage.php/home.php), where you put in your code.
here the difficult for me was to learn how wordpress is using more specific templates and templateparts (like using get_header('home') to use header-home.php instead of header) and with which weight-order they are used.
https://developer.wordpress.org/reference/functions/is_home/
https://codex.wordpress.org/Creating_a_Static_Front_Page
is_front_page() & is_home() can't help you ?
I want to verify if i'm on index.php page or home page in wordpress. I try with this code but doesn't work.
$homepage = "http://jocuri-copii.com/";
$currentpage = $_SERVER['REQUEST_URI'];
if($homepage==$currentpage)
{
$this->state = TRUE;
}
else
{
$this->state = FALSE;
}
I want to know if i'm on http://jocuri-copii.com/ and put state = true and else state = false. This method doesn't work.
You have two types of homepages:
The Posts Archive
A Page as homepage
To make sure that code runs as expected, independently of it being the posts archive or a page, you should do this on your theme's functions.php:
add_action ('wp', function () {
if (is_home() || is_front_page()) {
// Homepage
}
else {
// Not homepage
}
});
From is_home() reference page:
If a static page is set for the front page of the site, this function will return true only on the page you set as the “Posts page”.
From is_front_page() reference page:
If you set a static page for the front page of your site, this function will return true when viewing that page.
Try is_home() as referenced here
if (is_home()) {
# Do stuff
} else {
# Do other stuff
}
In WordPress, there are conditionals to verify the type of page requested by the viewer. For the home page, it depends upon how you have the Readings Settings (as found in Settings > Reading) configured.
is_home() is the "Posts Page"
is_front_page() is either
a static web page that you set as the primary home/front page
or the Posts Page
I know that's confusing. Let's walk through it. Go to the Settings > Reading admin page in the back-end of your website.
TIP
Here's a tip for you:
The Posts Page (the page that displays your latest posts, which is sometimes called "Blog") will **always* be true for is_home(). It is the "Home" Page. But it is not always the front page, as that is dependent upon how you setup "Reading Settings."
Default Setting
When you spin up a new WordPress website, the default setting is:
Front page display: set to "Your latest posts"
In this configuration, both is_home() and is_front_page() will be set to TRUE.
Setting Up a Static "Front Page"
If you define a static front page, then the conditionals are different.
The "front page" which is identified in the above example as "My Front Page" will do the following:
is_home() is FALSE
is_front_page() is TRUE
Notice that is_home() is not set. Why? Because is_home() really means "Posts Page." It does not mean "home page."
The Posts Page, which is identified in the above example as "Blog," will have the following states:
is_home() is TRUE
is_front_page() is FALSE
Front Page vs. Home Page
It's important to note the differences based upon how you have Reading Settings configured. If you want to see a video tutorial, I have one available for you here.
Remember, the is_home() function will always be true for the Posts Page. But it does not necessarily mean you are on the first, default page of your website.
Templates
WordPress has templates available for you to separate home from front page. You can use home.php and front-page.php.
However, from your index.php, you want to use the appropriate is_home() to note if you are the Posts Page or is_front_page() if you've defined a static front page.
I have set everything, including set the front page to "Home" page in reading setting, here is the screenshot:
And I added:
if( !is_home() && !is_front_page()) {
echo "string";
}
But I still get "string" at the top of home page, as you can see in the screenshot.
Could anyone tells me why?
Thanks for any helps :-)
is_front_page() returns true if the user is on the page or page of posts that is set to the front page on Settings->Reading->Front page displays
So if you set about us as the front page then this conditional will only be true if showing the about us page.
is_home() return true when on the posts list page, This is usually the page that shows the latest 10 posts.
If the settings under Front page displays are left at default then the home page will return true for both is_front_page() and is_home()
An example of using is_home():
You have set your posts page to a page called News.
A user navigates there and in the header you want to show additional
navigation
You could use is_home() to do this.
Example:
// Add below code in your functions.php
add_action('loop_start', 'Test_hook_check');
function Test_hook_check(){
if( !is_front_page() ) {
echo "string";
}
}
You need to use is_front_page() for static pages.
I have a javascript curl effect in place which loads an image and javascript file for the curl effect. But I want to appear in the post pages only.
So I want to do:
if this is a postpage{
load image;
load javascript;}
What is the way to do this in wordpress with php?
If you want to add it only to posts pages and homepages and your plug ins are troubling you..you might want to try
<?php if (is_single()|| is_home() || is_page()){ ?>
load image;
load js;
<?php } ?>
if you want it for only posts and pages, try
<?php if (is_single()|| is_page()){ ?>
load image;
load js;
<?php } ?>
not entierly sure what your after,
but you say you have the code ont he index.php page,
again un-sure has to, how you have this setup,
but if its only to be shown on a post or page or a postpage? (single post),
would be better to move your code into the header.php file? or have it only in the single.php file which means its only loaded when viewing a single post,
in turn it wont be shown on any other pages, except the single (full post) page..
then using the likes
if( is_single() ){
//then show - run your code?
}
?
Marty
Edit:
for both posts & pages then use
if( is_single() || is_page() ){
//then show - run your code?
}
this will only show your code when its a single post OR within a page.
In a previous post (Don't show this if the url contains the following) I asked how I would go about having my header echo a div if the user loaded a URL with /blog in the header.
What I didn't take into consideration, was that I don't want the div to display if its not just got /blog in the url, but if its any blog post, not just the index page of the blogs.
How do I run a bit of code from my header.php if the page I'm looking at is a blog post?
You would use the Wordpress functions is_single() and is_page.
if(!is_single() && !is_page() && !is_home() && !is_archive())
{
/* This will not display for any post, page, the home page, or an archive.
You can remove each is statement according to your needs */
}
For only posts, only use is_single, the same for page, home, and archive.
The full listing of is_statements can be found here. Here are some others:
is_home() : Home Page
is_front_page : Front Page
is_single() : Single Post
is_admin() : Admin Panel
is_sticky() : Sticky Post
is_page() : Page
is_category
is_tag
is_author
It's been long since I've played with wordpress but you can achieve a lot with using the conditional tags:
http://codex.wordpress.org/Conditional_Tags
Seems like is_single() might do what you want. Eg:
if (!is_single())
{
// display div
}