Shivaji Rao
Shivaji Rao

Reputation: 19

how to Wordpress slider code in header show only in homepage

Hi i am new bee in wordpress customization, here is the slider code, i want to insert this code in to header and show only on home page please healp me

 <?php

$slider_option = get_theme_mod('wp_store_homepage_setting_slider_option',0);
if ($slider_option == '1'):
    do_action('wp_store_slider_section'); // Slider section- this function is in wp-store-function.php
endif;
?>

Upvotes: 0

Views: 1822

Answers (3)

dExIT
dExIT

Reputation: 222

It would be much more simpler to just create ( if you dont have one ) a "HOME" page template, which is a fairly simple PHP page with a specific HEADING, so that you can choose that template when CREATING/EDITING pages.

Then in that code you add the part where you want your slider to show, and you can easily bypass these "is_home" or "is_frontpage" clauses.

Example :

<?php
/*
Template Name: NAME-OF-TEMPLATE
Author: NAME OF AUTHOR
Web Site: author url
Contact: author email
*/
get_header(); ?>
<!-- Get nav bar -->
<?php get_template_part( 'navigation', 'default' ); ?>
<!-- Start of page content -->
<div id="primary" class="site-content">
    <div id="content" role="main">
        <article id="post-0" class="post">
            <header class="entry-header">
<!-- Page Title/head if needed -->
            <!-- <h1 class="entry-title"><?php echo get_the_title(); ?></h1> -->
<!-- Your Code snippet -->
<?php
$slider_option = get_theme_mod('wp_store_homepage_setting_slider_option',0);
if ($slider_option == '1'):
    do_action('wp_store_slider_section'); // Slider section- this function is in wp-store-function.php
endif;
?>
            </header>
<!-- Main content -->
            <div class="entry-content">
<!-- Rest of your content and page structure -->
            </div><!-- .entry-content -->
        </article><!-- #post-0 -->
    </div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>

Please refer to this simple tutorial to help you familiarize your self : https://www.cloudways.com/blog/creating-custom-page-template-in-wordpress/

And WP referenses: https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-page-templates-for-specific-post-types

Upvotes: 1

Regolith
Regolith

Reputation: 2971

You can try is_home() or is_front_page() which will determine if it is home page

if ( is_home() || is_front_page() ) {
    $slider_option = get_theme_mod('wp_store_homepage_setting_slider_option',0);
     if ($slider_option == '1'):
     do_action('wp_store_slider_section'); // Slider section- this function is in wp-store-function.php
     endif;
} else {
    // Display what you want if not home
}

Look here for reference: is_home
Look here for reference: is_front_page

Upvotes: 0

Pawan Thakur
Pawan Thakur

Reputation: 591

// Use following code, is_front_page() returns true when viewing the Site Front Page.

 <?php if(is_front_page()) { 
        $slider_option = get_theme_mod('wp_store_homepage_setting_slider_option',0);
        if ($slider_option == '1'):
        do_action('wp_store_slider_section'); // Slider section- this function is in wp-store-function.php
        endif;
    } ?>

Upvotes: 0

Related Questions