Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I set static page as front page.

I need to know if user currently on homepage in my custom plugin.

Functions is_home() and is_front_page() doesn't works, since homepage is static page.

I can get an id of this page :

$frontpage_id = get_option('page_on_front');

But how to get id of current page from admin plugin? (Then i'll be able to compare those ids and detect if current page is homepage!)

2 vancoder Code:

1) Set any static page as frontpage.

2) Create dummy plugin

3) Code of plugin :

$d = is_front_page();
var_dump($d);

==> 

bool(false)

UPD

http://codex.wordpress.org/Conditional_Tags#The_Front_Page

should work, by didn't

2 Vancoder

Admin plugin means just plugin :) sorry

And those two lines is all context for now, try it yourself, it doesn't works.

WP version 3.3.2

share|improve this question
    
is_front_page() should work. Can you show some of your code? –  vancoder Apr 4 '13 at 21:04
    
I think you need to show your code in more context. is_front_page should work. –  vancoder Apr 4 '13 at 21:17
1  
What does your question mean by admin plugin? –  vancoder Apr 4 '13 at 21:18

2 Answers 2

up vote 2 down vote accepted

This is why I asked for more code context. I'll have to guess that you are checking for the front page outside of any hooked function, or inside a function that is called too early, before is_front_page() is ready.

The following will work.

function your_function()  {
$d = is_front_page();
var_dump($d);
}

add_action( 'wp', 'your_function' );
share|improve this answer
    
It works!!! Tnx, mate, saved a lot of time :) –  sbxmal Apr 4 '13 at 22:01

I guess you are talking about the editor screen? If so, you can use the global variable $post_ID:

add_action( 'edit_form_after_title', 'wpse_94626_front_page_detection' );

function wpse_94626_front_page_detection()
{
    global $post_ID, $post_type;

    if ( empty ( $post_ID ) or 'page' !== $post_type )
        return;

    if ( $post_ID === (int) get_option( 'page_on_front' ) )
        print '<p><b>This is the front page!</b></p>';
}

enter image description here

share|improve this answer
    
No, i talk about: when user loads any page on frontend, i should detect if this is homepage (in my custom plugin) –  sbxmal Apr 4 '13 at 21:15
    
@sbxmal You cannot get to the front page page; WordPress will redirect that request to the front page automatically, and then is_front_page() is true. –  toscho Apr 4 '13 at 21:20
    
Maybe, i explained this not really clearly. I have plugin with code above ($d = is_front_page(); var_dump($d);). When i go to homepage of the site, i want to check in plugin is it really homepage or any other page. Homepage is set as static page. –  sbxmal Apr 4 '13 at 21:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.