is_home() is not working in functions.php

Sangwan Pankaj Reply 04:15
At the time functions.php is included during bootup, WordPress has no idea on the contents of the query, and doesn't know the nature of the page. is_home will return false.

Wrap the code in a function and have it triggered by the wp hook, which comes after the global query object has been hydrated with data.


add_action( 'wp', 'check_homepage' );
function
check_homepage() {
    if ( is_home() )
        add_action( 'wp_enqueue_scripts', 'my_scripts' );
}

Related Posts

Wordpress 721304243806057191
Copyright by GhostPHP. Powered by Blogger.

Search

Recent Post

Popular Posts

Follow us