How to check if current static page is frontpage from admin plugin

I set static page as front page.

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

Read More

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

Related posts

Leave a Reply

2 comments

  1. 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' );
    
  2. 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