You can use the global $template
. The following function returns the basename
of the template file being used: index
, archive
, etc.
function get_template_name_wpse_85011()
{
global $template;
$filename = basename( $template, '.php' );
return $filename;
}
And use it in your template with something like:
$templat = get_template_name_wpse_85011();
switch( $templat )
{
case 'index':
// do index
break;
case 'archive':
// do archive
break;
default:
break;
}
Related Posts:
- How to get the id or url of the image in an image post?
- has_post_format() vs. get_post_format()
- What difference does it make if I enable support for video post format?
- How do I remove the post format meta box?
- Adding post-formats to Twenty Ten child theme
- Is there a real life use case for post formats except for microbloging?
- Renaming post formats after Gutenberg
- What is the recommended behavior for the post formats?
- Custom Post Formats
- Target all posts that are NOT aside or link post formats
- Link Featured Thumb to Attachment Page, If Possible
- Filter the first from Quote Post Format
- Displaying all Video Post Formats to Page
- Display Post Format as a String
- Different markup for each post format
- post formats – how to get the relevant content part?
- Post formats for Pages not saving
- Is there any problem if I use get_template_part like this?
- How can I remove the first video from a post and feature it?
- previous_post_link/next_post_link disappear when excluding by post_format
- Usage of post_formats
- how to get list of post formats supported by theme?
- Formatting Standard Post Format
- If post-format == ‘gallery’ conditional
- Adding new post format on plugin activation
- post formats – where’s the difference: “aside” vs. “status”?
- how to retrieve the image title for image Post Format
- About post format
- Smart post format loop problems
- “post-format” code snippets list [closed]
- wordpress post formats
- How to display quote format by preg_match function?
- I would like to have a quote page just to show quotes
- Return only one post format in index.php [duplicate]
- How to display list of video post on video section?
- Paste from word not preserving formatting
- How to treat post formats?
- Post formats and template hierarchy
- Change standard post format metabox
- Next Post Link in format
- Mass post format changer?
- Displaying cf post formats with oembed
- Custom formatting
- Missing feature image link function
- show hide image script after 4 seconds [closed]
- How can I add an image upload field directly to a custom write panel?
- Is There a Difference Between Taxonomies and Categories?
- Restricting users to view only media library items they have uploaded?
- How do I disable responsive images in WP 4.4?
- How To Retrieve An Image Attachment’s Alt Text?
- Filter to remove image dimension attributes?
- How to get a list of all the possible thumbnail sizes set within a theme
- How to get image title/alt attribute?
- User-friendly cropping of post thumbnails?
- WordPress Theme Preview Image
- How do I get the avatar URL instead of an HTML IMG tag when using get_avatar?
- Image Upload from URL
- Programmatically adding images to media library
- How do I delete all UNUSED images from my uploads directory?
- Set default image sizes in WordPress to hard crop
- Is it possible set a featured image with external image URL
- How to generate thumbnails when needed only?
- get attachment title based on attachment id
- How can I make add_image_size() crop from the top?
- Resizing images to the actual size used in the editor?
- No Thumbnails Generated
- wp.media.view.ImageDetails – Save settings as HTML5 data-* attributes for image
- How to Require a Minimum Image Dimension for Uploading?
- How to disable WordPress from creating thumbnails?
- add_image_size() for specific Post Types
- Stop wordpress from hardcoding img width and height attributes
- Creating an Image-Centric Custom Post Type?
- How does WP media uploader create the 3 different sized images, and how can I duplicate it
- Handle issues with change of image scaling (rounding) in 4.1 (WP Ticket #18532)
- Programmatically get images by URL and save in uploads folder
- Prevent WordPress from generating medium_large 768px size of image uploads?
- How do you get the post thumbnail size?
- remove or update add_image_size
- Get Image Description
- How to extend the gallery block in Gutenberg?
- Image quality based on image size
- Function to get URL of original uploaded image – full size
- how to get original image using wp_get_attachment_image_src
- set_post_thumbnail_size vs add_image_size
- What is a good alternative to using $content_width for image optimization?
- Minimum Dimensions Requirement for Featured Image?
- get the attachement url for the medium sized image
- Add image size if page template
- Can I attach image to post without adding it to post?
- Automatically replace original uploaded image with large image size
- The the_post_thumbnail without srcset?
- WordPress crop tool greyed out
- Generate Thumbnails only for Featured Images
- Get the first image from post content (eg.: hotlinked images)
- How to get all featured image sizes and their URLs?
- How to scale up featured post thumbnail?
- Upload images to remote server
- removing inline styles from wp-caption div
- How to disable generation of default image sizes for some custom post types?
- How to Dynamically Resize WordPress Image On-The-Fly (custom field/theme option)