WordPress.org

Forums

is_front_page and is_home not working in includes/theme-header.php (3 posts)

  1. nathanduckett
    Member
    Posted 2 years ago #

    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

  2. wpismypuppet
    Member
    Posted 2 years ago #

    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.

  3. nathanduckett
    Member
    Posted 2 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.