admin管理员组文章数量:1124383
Using 2016. For Search and Archive and Index, all attachment posts use content-attachment to display the excerpt... as expected.
But when I go to the actual attachment, it uses the image.php template. How can I get the post to use the same template as in archive or index or search? (content-attachment)?
Using 2016. For Search and Archive and Index, all attachment posts use content-attachment to display the excerpt... as expected.
But when I go to the actual attachment, it uses the image.php template. How can I get the post to use the same template as in archive or index or search? (content-attachment)?
Share Improve this question asked Mar 7, 2024 at 21:42 jchwebdevjchwebdev 7752 gold badges14 silver badges33 bronze badges 2 |1 Answer
Reset to default 1There's a couple things you could do. If we follow the Template Hierarchy you could rename your content-attachment.php
file to attachment.php
and remove image.php
. This will ensure that the image view will fallback to attachment.php
.
If you want to use content-attachment.php
then you could use the template_include
hook to tell WordPress to load in which situation.
/**
* Tell WordPress to load a specific template under specific circumstances.
*
* @param String $template_path
*
* @return String $template_path
*/
add_filter( 'template_include', function( $template_path ) {
if( false !== strpos( $template_path, 'image.php' ) ) {
// Path to your PHP file, relative to the twentysixteen theme (or child theme)
// This would mean `content-attachmetn.php` is in the twentysixteen root, with page.php and singe.php
$template_path = get_template_part( 'content-attachment' );
}
return $template_path;
} );
本文标签:
版权声明:本文标题:templates - In 2016 theme, how can I force all single attachment posts to use content-attachment.php rather than image.php? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736623312a1945620.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
content-attachment.php
file. You could rename the image.php to something WordPress doesn't recognize and see what it falls back to. See the Template Hierarchy for more information. – Howdy_McGee ♦ Commented Mar 7, 2024 at 23:26