Detecting index.php specifically may not be the best option because this template file is used in many cases in WordPress. Eventually, all pages will fall back to using index.php if no other template file is associated with this page.
So instead of targeting index.php, get familiar with template hierarchy and try to use conditional tags, whenever possible.
For example, if you want to display the banner only on archive pages you could do something like:
<?php if ( is_archive() ) : ?>
<div id="banner">
<!-- Banner content goes here. -->
</div>
<?php endif; ?>
Similarly, you can combine conditional tags:
<?php if ( is_front_page() && is_home() ) : ?>
<div id="banner">
<!-- Banner content goes here. -->
</div>
<?php endif; ?>
This way your code will be future-proof and compliant with WordPress Coding Standards.
Related Posts:
- How to remove search bar from a wordpress theme? [closed]
- Template for individual post designs
- Why is the `if else` not working?
- WP 3.4 – what action/hook is called when theme customisation is saved?
- Add a dropdown to theme customizer
- Is it good to rename theme folder downloaded from WordPress.org?
- What is the problem if I use CDN in my WordPress parent theme(built using bootstrap)?
- Is it possible to use line break in theme description?
- Is the theme customizer slowing down my site?
- How can I get wp_head() as a string instead of echoing it?
- What is the best book to learn how to make themes for wordpress?
- Grab the first paragraph of each post
- How to check if post has any tag?
- How do I “unhook” / de-register jQuery so that it’s not called as part of wp_footer();?
- Example of a theme organization without all the default wp files in root
- Which is the simplest theme for WordPress to use it as your base?
- “Cheatin’ uh?” error message on multple theme directories
- How to tell if the user is an admin?
- Adding WordPress colorpicker in widget settings
- Disable the Custom Internal CSS added by theme.json for Certain Pages
- Unwanted blank lines before tag
- A theme that follows all the best practices to learn from?
- get_post() function returns post even if it is trashed
- How to highlight the current page in the nav menu?
- “Display Site Title and Tagline” checkbox not working?
- Add social icons in a theme through custom admin menu
- file_get_contents Not allowed in Themes?
- Custom Nav Walker Displaying Values in Sub Menu
- How to configure wordpress to work with Vuejs with SSR and without hashbang
- How do I remove twentyten without ruining what I did?
- Custom theme not visible in Appearance
- Some doubts about how to show posts in a custom theme?
- Why are theme templates organized as multiple point of entry PHP files instead of reusing your theme’s index.php?
- Can’t delete theme
- How to add a second stylesheet to the editor
- Developing WordPress Theme using CSS framework like Bootstrap
- WP_Customize_Color_Control omitting # symbol
- Single Page theme [closed]
- Theme translation not applying
- How to add filter the post thumbnail before save in database?
- Can I have two different theme for two different language?
- Storefront child theme not applying parent theme [closed]
- Catagories to the list of the titles in that catagory to the content of the post [closed]
- WP_Comment_Query – Get comments and answers separately
- excerpt() shows different result between remote and localhost(development environment)
- Theme Javascript.php Overwritten Nightly [closed]
- Theme Inspector “X-Ray”
- Acivate all themes multisite wide automatically
- How to place HTML tags in content from the_content()?
- WordPress Theme Creation [closed]
- What is the meaning of WordPress’s recommended css classes and where are they applied?
- Integrate WooCommerce theme with a WordPress theme [closed]
- Automated Footer information
- How do you use WordPress for a website that’s not in a blog format?
- Managing WordPress Theme
- theme style is applied on the dhasboard rather than the website
- Alignment Problem [closed]
- What $handle does WordPress use for a theme’s implicit style.css?
- How to track a users last visited page?
- In a Gallery with limited image posts, how do I not limit images on single post?
- LESS not working in WordPress [closed]
- Unwanted empty line at the beginning of document
- How to add custom page elements to the WYSIWYG editor?
- Why is my container argument not working for wp_nav_menu() [closed]
- Why I obtain different visualization when I run the website on my local machine and on remote server?
- How to use the _S framework
- help needed for suit designing tool
- Open portfolio image in light box
- Let visitors show/hide a type of content
- Best practice for implementing a blog page / section in wp_menu_nav()
- How to modify theme content in Thematic?
- how to add a badge on product based on filter?
- how to create/register menu items that can be added to menus later
- My wordpress theme name isn’t updating straight away
- Why nav_menu_css_class doesn’t work with apply_filters?
- WordPress and Semantic UI
- Customizer API Multi Sections in single Panel
- WordPress theme options checkbox default checked state
- Theme does not allow shortcodes
- Text widget is placing everything side by side. I want to post it above
- What is an alternative to not using child theme to customize a WordPress theme?
- Adding a second logo next to the main one in header
- Creating a theme just to deploy a single page
- Menu names not getting translated
- How to generate a rtl.css file for themes?
- Get property of non-object on theme activation
- change wordpress website logo url [duplicate]
- wp_editor some functionality not working on custom theme
- Update modified Shopify third-party theme [closed]
- Weird ‘theme update’ error [duplicate]
- “No Data Received” error in Chrome every time i try to update the theme functions file
- WordPress two sidebar layout or theme
- Standard Way To Do Custom Work Within A Page?
- Confused on loading page content
- Add Dynamic Sidebar to Exisiting WordPress Theme [closed]
- How can I install my custom-made theme on a wordpress.com blog? [closed]
- Why am I getting posts back when I shouldnt
- HTML to WORDPRESS [closed]
- .submenu class missing in output from wp_nav_menu
- What is the point of using the front-page.php template? [closed]