php使div类'header-ads'仅显示在wordpress主页上

On my wordpress blog there is a specific div class called header-ads How can I make the HTML snippet below only show on my sites homepage using php, and which theme file should I put the code in.

Since using the display:none css property is against adsense policies i need to use php. As the entire ad code snippet will than be completely eliminated from the post's html assuming the publisher has removed it.

<div class="header-ads">

<!--Ad Code-->

</div>

</div>

Create like this:

# wp-content/plugins/homepage-ads
# wp-content/plugins/homepage-ads/homepage-ads.php

<?php
    /**
     * Plugin Name: Home Page Ads
     * Description: Module to enable ads on home page
     * Version:     1.0
     * Author:      Vendor
     * License:     GPL2
     */

    class homepage_ads
    {
        private static $instance;
        protected      $templates;

        private function __construct()
        {
            $this->templates = array();

            if (version_compare(floatval(get_bloginfo('version')), '4.7', '<' )) {
                add_filter('page_attributes_dropdown_pages_args', array($this, 'register_project_templates'));
            } else {
                add_filter('theme_page_templates', array($this, 'add_new_template'));
            }

            add_filter('wp_insert_post_data', array($this, 'register_project_templates'));
            add_filter('template_include',    array($this, 'view_project_template'));
        }

        public static function get_instance()
        {
            if (self::$instance == null) {
                self::$instance = new homepage_ads();
            }

            return self::$instance;
        }

        # add templates added in __construct to wp
        public function add_new_template($posts_templates)
        {
            $posts_templates = array_merge($posts_templates, $this->templates);
            return $posts_templates;
        }

        public function register_project_templates($atts)
        {
            $cache_key = 'page_templates-'. md5(get_theme_root() .'/'. get_stylesheet());
            $templates = wp_get_theme()->get_page_templates();

            if (empty($templates)) {
                $templates = array();
            }

            wp_cache_delete($cache_key , 'themes');

            $templates = array_merge($templates, $this->templates);

            wp_cache_add($cache_key, $templates, 'themes', 1800);

            return $atts;
        }

        public function view_project_template($template)
        {
            if (is_search()) {
                return $template;
            }

            global $post;

            if (!$post) {
                return $template;
            }

            if (!isset($this->templates[get_post_meta($post->ID, '_wp_page_template', true)])) {
                return $template;
            }

            $file = plugin_dir_path( __FILE__ ). get_post_meta($post->ID, '_wp_page_template', true);

            if (file_exists($file)) {
                return $file;
            } else {
                echo $file;
            }

            # return template
            return $template;
        }
    }

    function add_home_page_ads()
    {
        $html  = '<div class="ads">';
        $html .= '    <img src="" />';
        $html .= '</div>';

        echo $html;
    }

    add_action('home_page_ads', 'add_home_page_ads');

now you have a function home_page_ads available to use, then you can create a template file and call it like home_page_ads() and it will render