我知道如何使用comment_form_defaults
, 但我不知道如何使自定义帖子类型与常规帖子有所不同。此外,我希望在我的评论中使用不同的措辞。php文件。有可能得到评论吗。php文件对于自定义的帖子类型不同,像你可以做页眉和页脚吗?
如何根据帖子类型更改评论表单标题
1 个回复
SO网友:butlerblog
您可以使用comment_form_defaults
筛选以根据自定义帖子类型更改文本。只需检查过滤器函数中的post类型。
例如:
add_filter( \'comment_form_defaults\', \'my_comment_form_defaults\' );
function my_comment_form_defaults( $defaults ) {
if ( \'my_cool_custom_post_type\' == get_post_type() ) {
$defaults[\'title_reply\'] == \'My Custom Post Type Comment Title\';
}
return $defaults;
}
如果需要更改默认值的各种元素,请参见$defaults
是在源中应用过滤器挂钩之前定义的:https://core.trac.wordpress.org/browser/tags/5.7.1/src/wp-includes/comment-template.php#L2429而不是加载不同的注释。基于post类型的php,您可以使用switch()
或if()
逻辑基于get_post_type()
根据请求的帖子类型进行不同的显示。