我想在'内容编辑器'中生成一个占位符文本,如果post有post格式'gallery'。但是我不能使它工作:
:显然也
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;
}
}
应该这样做:
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;
}
另外,请确保您的主题设置为实际具有post-format支持add_theme_support,并且您的帖子具有正确的帖子格式(图库)。