我試圖創建函數來替換自定義帖子類型WordPress Storefront子主題的內容顯示,但如果條件不起作用! 評論如果陳述是我所嘗試過的。函數替換內容顯示爲自定義帖子類型
//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