0

I am trying to add functions to wp_footer based on the the page id. I am hooking my callback to init, but its not working. Here is what I am using.

function fl_template_loader() {

    if ( is_page( 1032 ) ) {
        add_action( 'wp_footer', 'fl_theme_midnight' );
    }
    if ( is_page( 1032 ) ) {
        add_action( 'wp_footer', 'fl_theme_passion' );
    }
}
add_action( 'init', 'fl_template_loader', 0 );

What I am doing wrong? Is the init firing too early or too late? I tried to hook in plugins_loaded (for early execution) and wp_loaded (for later execution), but all failed.

  • 1
    Try using wp hook instead of 'init'. – Nilambar Sep 1 '14 at 6:30
2

You will have to use wp_footer action for that. And check your pages in functions itself to perform some specific tasks. something like this.

function my_footer_function() {

  if ( is_page( 1032 ) ) {

    // Do this

  } elseif ( is_page( 1033 ) ) {

    // Do that

  } else {

    // Do something else or nothing

  }

}
add_action( 'wp_footer', 'my_footer_function', 100 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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