WordPress.org

Support

Support » How-To and Troubleshooting » is_front_page and is_home not working in includes/theme-header.php

is_front_page and is_home not working in includes/theme-header.php

  • nathanduckett

    @nathanduckett

    Hi,

    I am trying to remove sharethis script from the head section on the homepage (index.php).

    I would like to only have it load the script on the single blog posts and single custom post type.

    I have tried the following:

    if (get_option('jr_sharethis_id') && !is_front_page())
        add_action('wp_head', 'jr_sharethis_head');
    if (get_option('jr_sharethis_id') && !is_home())
        add_action('wp_head', 'jr_sharethis_head');
    if (is_front_page()) {} else {
                      if (get_option('jr_sharethis_id'))
                      add_action('wp_head', 'jr_sharethis_head');
                           }
    if (is_home()) {} else {
                      if (get_option('jr_sharethis_id'))
                      add_action('wp_head', 'jr_sharethis_head');
                           }

    None of these methods seem to work? I am using this in my theme folder:
    includes/themeheader.php

    Any suggestions?

    Thanks Nathan

Viewing 2 replies - 1 through 2 (of 2 total)
  • wpismypuppet

    @wordpressismypuppet

    Why not try:

    if( get_option( 'jr_sharethis_id' ) && is_single() )
        add_action( 'wp_head', 'jr_sharethis_head' );

    Since you only want it on single posts… this code will also work for any single custom post page as well.

    nathanduckett

    @nathanduckett

    Hi, tried

    if( get_option( 'jr_sharethis_id' ) && is_single() )
        add_action( 'wp_head', 'jr_sharethis_head' );

    It works and removes it from the head section of the site but also removes it from every other page including the single posts, i cant understand why the code i mentioned did not work and your suggestion also should work.

    I have used the is_front_page to remove the home link from the home page and that works fine!

    so any other suggestions much appreciated.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘is_front_page and is_home not working in includes/theme-header.php’ is closed to new replies.
Skip to toolbar