我尝试创建功能来替换自定义帖子类型 WordPress Storefront 子主题的内容显示,但 if 条件不起作用!注释的 if 语句是我尝试过的。
//if (is_singular() && (get_post_type() == 'gallery')) {
add_action( 'init', 'customise_storefront' );
//}
function customise_storefront() {
//if(get_post_type( $post->ID ) == 'gallery'){
//if('gallery'== get_post_type()) {
//if (is_singular('gallery')) {
//if (is_single('gallery')) {
//if (is_singular() && (get_post_type() == 'gallery')) {
// Remove the storefromt post content function
remove_action( 'storefront_single_post', 'storefront_post_content', 30 );
remove_action( 'storefront_loop_post', 'storefront_post_content', 30 );
// Add our own custom function
add_action( 'storefront_single_post', 'gallery_post_content', 30 );
add_action( 'storefront_loop_post', 'gallery_post_content', 30 );
//}
}
/* Gallery post content*/
if ( ! function_exists( 'gallery_post_content' ) ) {
function gallery_post_content() {
?>
<div class="entry-content" itemprop="articleBody">
<?php
the_content(
sprintf(
__( 'Continue reading %s', 'storefront' ),
'<span class="screen-reader-text">' . get_the_title() . '</span>'
)
);
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'storefront' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<?php