user677607
user677607

Reputation:

need help with wordpress add_action init to recognise is_single

I have,

function my_function_init(){
    global $post;
    if(is_single()) {
        echo $post->ID;
    }
}
add_action('init', 'my_function_init');

this doesn't work for me, it doesn't recognize if its a post even if its a post (is_single() = checks if its a post), i have this in the plugin i am writing for wordpress, please help

Upvotes: 1

Views: 2806

Answers (1)

user677607
user677607

Reputation:

I got it the solution is

add_action('get_header', 'my_function_init');

thats the fix :)

Upvotes: 8

Related Questions