• I simply need a plugin to check is the blog is on the homepage or not
    Google it and not much look there.

    The code…

    is_front_page()

    returns this ??

    Notice: is_front_page was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in C:\xampp\htdocs\wordpress\wp-includes\functions.php on line 3049

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • is_front_page()

    edit: nvm, your spelling error is just in the title.

    you’re calling it before your sites being loaded basically. where are you putting this?

    Thread Starter phillbooth

    (@phillbooth)

    Hello David,

    I am using this in a plugin that loads some jquery code for a slider, it would be helpful to have is_front_page to prevent the code appearing on every page but the home page

    within that plugin

    if ( is_front_page() ) { ... }

    can’t be called at say, wrapped around the entire plugin, it’s best to put it before it outputs, like in a hook or filter where the plugin tries to output.. I don’t know what the code of the plugin looks like, but I imagine it’s something like i.e.:

    add_action('the_content','add_slideshow');
    function add_slideshow() {
      if ( is_front_page() ) {
        ..
      }
    }
    Thread Starter phillbooth

    (@phillbooth)

    Sorry for the delay in getting back to you

    add_action( ‘plugins_loaded’, array( ‘mytheme_slider_Widget_Loader’, ‘load’ ) );

    so yes, plugins_loaded is too early of a hook for a is_front_page() argument.

    try init or wp hooks. I can’t guarantee they’ll work, as I’m not sure what mytheme_slider_Widget_Loader needs/does/etc.

    add_action( 'init', array( 'mytheme_slider_Widget_Loader', 'load' ) );
    //or
    add_action( 'wp', array( 'mytheme_slider_Widget_Loader', 'load' ) );
    Thread Starter phillbooth

    (@phillbooth)

    Hello David,

    ‘wp’ worked like a brilliantly, so I can now place CSS and JS hooks
    only on the homepage. Thanks for your help

    add_action( 'wp', 'mytheme_carousel_add_frontend' );
    function mytheme_carousel_add_frontend()
    {
    if(is_front_page() || is_home())
    {
    add_action( 'wp_enqueue_scripts', 'mytheme_add_carousel_core_css',1 );
    add_action('wp_footer', 'mytheme_add_carousel_options_content' ,20);
    }
    }

    I forgot where I got this from but it’s a list of hooks, in fire order. My IDE has a shortcut for referencing this list so I can quickly know where to add certain actions.

    // -----------------
    // muplugins_loaded
    // plugins_loaded
    // sanitize_comment_cookies
    // setup_theme
    // load_textdomain
    // after_setup_theme
    // auth_cookie_malformed
    // set_current_user
    // init
    // widgets_init
    // register_sidebar
    // wp_register_sidebar_widget
    // wp_loaded
    // parse_request*
    // send_headers*
    // parse_query*
    // pre_get_posts*
    // posts_selection
    // wp*
    // template_redirect
    // get_header
    // wp_head
    // wp_enqueue_scripts
    // wp_print_styles
    // wp_print_scripts
    // get_template_part_loop
    // loop_start*
    // the_post*
    // loop_end*
    // get_sidebar
    // dynamic_sidebar
    // get_search_form
    // wp_meta
    // get_footer
    // twentyten_credits
    // wp_footer
    // wp_print_footer_scripts
    // shutdown

    please mark this post as resolved.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘programmatically use if_front_page in a plugin’ is closed to new replies.