WordPress:按帖子格式显示占位符文本

时间:2016-10-24 13:12:16

标签: php wordpress function post-format

如果帖子有帖子格式'gallery',我想在'内容编辑器'中生成占位符文本。但我无法让它发挥作用:

的functions.php:

add_filter( 'default_content', 'wpse57907_default_content', 10, 2 );
function wpse57907_default_content( $content, $post ) {
    if ( 'post' == $post->post_type && has_post_format('gallery')) {
        $content = '<i style="color:#999">Use this area to upload and edit images... any text put in here will NOT be generated on the project&apos;s page. Please use the fields above for text.</i>';

    return $content;
    }
}

1 个答案:

答案 0 :(得分:0)

这应该这样做:

add_filter( 'default_content', 'wpse57907_default_content', 10, 2 );
function wpse57907_default_content( $content, $post ) {
    $format = get_post_format($post->ID);
    if ( 'post' == $post->post_type && $format == 'gallery') {
        $content = '<i style="color:#999">Use this area to upload and edit images... any text put in here will NOT be generated on the project&apos;s page. Please use the fields above for text.</i>';
    }
    return $content;    
}

此外,请确保您的主题设置为实际上具有add_theme_support的格式后支持,并且您的帖子具有正确的帖子格式(图库)。