Simple function display only home page

I have a simple function that I need to assign to a hook, and then have it appear only on the home page.

I just cannot seem to get it right.

Read More
add_action( 'woo_content_before', 'woo_add_home_slider' );

function woo_add_home_slider () {
    if ( function_exists( 'soliloquy_slider' ) ) soliloquy_slider( '169' ); 
}

I need this to only show on my homepage.

Related posts

Leave a Reply

1 comment

  1. To make your function display only on the home page, you would use the WordPress function is_home() and/or is_front_page, depending on your home page settings.

    If your home page is set to list your blog posts, then this would be your solution:

    function woo_add_home_slider() {
        if (is_home()) {
            if ( function_exists( 'soliloquy_slider' ) ) soliloquy_slider( '169' ); 
        }
    }
    

    If your home page is set to display a specific page:

    function woo_add_home_slider() {
        if (is_front_page()) {
            if ( function_exists( 'soliloquy_slider' ) ) soliloquy_slider( '169' ); 
        }
    }
    

    Or, depending on your settings, you might be able to get the effect you want by combining the two with an or:

    If your home page is set to list your blog posts, then this would be your solution:

    function woo_add_home_slider() {
        if (is_home() || is_front_page()) {
            if ( function_exists( 'soliloquy_slider' ) ) soliloquy_slider( '169' ); 
        }
    }
    

    Of course, you could combine the ifs into a single condition, like so:

    function woo_add_home_slider() {
        if ((is_home() || is_front_page()) && function_exists( 'soliloquy_slider' )) {
            soliloquy_slider( '169' ); 
        }
    }