最近有人发现模板兔对于modown主题的二次开发,需要修改评论显示。 如果想在不影响主题升级的情况下进行修改,则需要使用子主题。
如何使用子主题覆盖默认评论模板函数comments_template引用的模板文件?
在子主题的functions.php中添加如下代码,然后在子主题中创建comments-new.php文件。
add_filter( "comments_template", "modown_child_comment_template" );
Products
GG网络技术分享 2025-03-18 16:05 0
最近有人发现模板兔对于modown主题的二次开发,需要修改评论显示。 如果想在不影响主题升级的情况下进行修改,则需要使用子主题。 如何使用子主题覆盖默认评论模板函数comments_template引用的模板文件? 在子主题的functions.php中添加如下代码,然后在子主题中创建comments-new.php文件。add_filter( "comments_template", "modown_child_comment_template" );
function modown_child_comment_template( $comment_template ) {
global $post;
if ( !( is_singular() && ( have_comments() || 'open' == $post->comment_status ) ) ) {
return;
}
return dirname(__FILE__) ."/comments-new.php";
}Demand feedback