如果帖子有帖子格式'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's page. Please use the fields above for text.</i>';
return $content;
}
}
答案 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's page. Please use the fields above for text.</i>';
}
return $content;
}
此外,请确保您的主题设置为实际上具有add_theme_support的格式后支持,并且您的帖子具有正确的帖子格式(图库)。