Filter attachment_template
and return your custom path. For details, see wp-includes/template.php
, function get_query_template()
.
Sample code:
add_filter( 'attachment_template', function( $template )
{
global $post;
// inspect $post object to determine the correct template
// and change the file path, then:
return $template;
});
Related Posts:
- Opinions and recommendations on the best barebones base theme [closed]
- Dynamic template serving, change theme_root using add_filter from current theme
- How to override the “inc” folder (or any folder) in a theme using child theme?
- Is it possible to access Gutenbergs reusable blocks in CPT block templates?
- Loading template files from a subfolder in my theme?
- WordPress as Backend, Laravel Front End: How to connect Routes?
- Can I obtain differents links for different installed theme?
- WordPress ignoring specified template for front page. Why?
- Can I apply a WP theme to a specific custom page template?
- WordPress Fatal error: Call to undefined get_header() in index.php on line 15 [closed]
- Change Theme from Plugin based on query_vars
- How to add template to theme in WP
- Added a new template file to a theme – get Call to undefined function error
- How to find a file in WordPress themes [closed]
- Display a specific dynamic sidebar widgets on a specific page
- Child theme Page Template not loading
- Creating new templates in child themes breaks layout
- Get WordPress to use another custom “author.php” file (“custom-author-file.php”)
- Search form not finding content in template page
- display comment form for specific post id
- Selected template is not respected for home page in WordPress
- Putting two themes together to create a complete site
- Is there a way to upgrade a theme without losing custom templates?
- Need help with making a website where user can add products
- Advantages of wordpress theme vs wordpress as a backend only [closed]
- What’s a good way to unenqueue all scripts for a single template page?
- Using the same database on another Subdomain
- Trying to fix a website that was built with WordPress and then taken off of it
- Conditional config WP_HOME/WP_SITEURL does not update bloginfo(‘template_url’)?
- Multiple sub directories for theme template pages
- How to remove the tripadvisor logo from the wordpress theme?
- Please help me clear my confusions about WordPress
- WordPress 2022 template, how to see the blocks added in post template on post edit?
- Can I use non-wordpress themes in WordPress?
- WordPress keeps switching back to empty template
- Removing a widget via theme editor
- How do I bring a page template into a new theme with separate styling?
- 12 column grid layout
- Theme Dev | Convert Template to Theme
- Revamping a WordPress mirror site – and I don’t know where to start!
- What is the template file for topic layouts in bbPress?
- Will this js code work in a page template?
- How to find out which template the HTML content comes from?
- Create a child Theme or custom Theme
- How to modify/ customise NextGen Gallery’s templates? [closed]
- wordpress template page Usage [duplicate]
- Overwrite template-tags.php in child theme
- What happens to bespoke page template references on theme change?
- How to add sidebar to homepage programmatically?
- Get header/footer list for a theme
- Homepage not loading correctly, only after refreshing
- How to clone a theme template from within WordPress? [closed]
- W3 Total Cache, CDN and theme files [closed]
- What are nulled themes?
- Copying theme from Localhost to Live does not copy all theme settings with it?
- Making the Header on the Twenty Ten Theme Less Tall?
- Register theme customizer settings when theme activates [duplicate]
- hfeed CSS class in Twentyeleven Theme
- Which is the most well coded and semantically correct naked/blank WordPress theme (based on WordPress coding standards)?
- How to change the themes “Live Preview” url within the Appearance->Themes page?
- How do I apply my CSS to a theme page?
- How to get the post-ID in my plugin?
- Parallax WordPress theme without hardcoding – possible?
- Embedded Videos (PB) – Not Available
- Recommended Themes for a Developer-related Topics Blog?
- none of my css is working in my child theme
- Upgrading from 2.9.4 to 3.0.x and with a custom theme
- Plugin-generated pages use Not Found or Pages Archive templates?
- How to use one theme for multiple WordPress sites?
- Need to edit themes HTML code
- Newbie wordpress question re banner height
- How to add custom JS file in WordPress Child theme with get_theme_file_uri
- Adding the jQuery to my theme that already exists in WordPress?
- Interpretation and explanation of register sidebar
- Removing the references to the wp-content folder
- get_pages Not accepting my query
- Date based CSS/theme
- Functions.php error – when trying to change the theme
- Make a menu item unselectable
- conditional statement if wordpress theme block is empty then hide block
- jQuery is not defined – some theme features do not work!
- How can I modify the CSS only for the search results page of WordPress?
- SVG icons in Twenty Nineteen
- Does anyone know where to find the area to edit this text
- fixing page URL’s
- Don’t prepend WordPress base url to image paths
- Issues with dynamic widget in theme customizer
- How to Solve the WordPress Cron Job Site Slow down Problem?
- How do I get the path to the currently in use theme’s directory?
- Pagination not working in home page
- Show part of front page on another page [closed]
- Premium theme – hardcoded url?
- Any Mobile Theme Switcher – Theme not complete (Stylesheet missing)
- permissions on themes directory
- Categorising themes by folders in backend
- Theme Options Menu Item – Permission Issue
- totally confused about editing wp theme….new guy to wp
- Divi Template A Few Questions
- Header Paperpunch theme disappers with IE9 [closed]
- Why does twentysixteen take a free hand in dealing with longstanding usability principles? [closed]