admin管理员组文章数量:1126455
I have this in my functions.php
/*Remove website field from comment*/
function xyzmark_remove_url($fields) {
if(isset($fields['url'])){ unset($fields['url']); }
return $fields;
}
add_filter('comment_form_default_fields', 'xyzmark_remove_url');
Below is screenshot of comment form. It has no website url
field as intended
But I still get url when someone post comment. Below is screenshot of email I got
Not sure how to completely disabled this comment field so that I can get rid of spammers posting links in comment form url field.
Note: I am using custom coded theme.
I have this in my functions.php
/*Remove website field from comment*/
function xyzmark_remove_url($fields) {
if(isset($fields['url'])){ unset($fields['url']); }
return $fields;
}
add_filter('comment_form_default_fields', 'xyzmark_remove_url');
Below is screenshot of comment form. It has no website url
field as intended
But I still get url when someone post comment. Below is screenshot of email I got
Not sure how to completely disabled this comment field so that I can get rid of spammers posting links in comment form url field.
Note: I am using custom coded theme.
Share Improve this question asked Jun 25, 2023 at 4:19 sanjay ojhasanjay ojha 1851 silver badge8 bronze badges2 Answers
Reset to default 1The code you've provided does remove the website URL field from the comment form. However, bots can still directly POST to the wp-comments-post.php
file with a URL included. To prevent this, you can remove the URL from the submitted data before it's saved to the database. You can achieve this using the preprocess_comment
filter.
Add the following code to your theme's functions.php file:
function xyzmark_remove_comment_author_url( $commentdata ) {
$commentdata['comment_author_url'] = ''; // remove the URL from the submitted data
return $commentdata;
}
add_filter('preprocess_comment', 'xyzmark_remove_comment_author_url');
This code will ensure that even if someone (or a bot) directly submits a comment with a URL, it will be removed before the comment data is saved. Note that this won't affect the ability of admins to manually add URLs to comments from within the WordPress admin interface.
This is what worked for me for my GeneratePress site.
function xyzmark_remove_comment_author_url($commentdata) {
// Remove the URL from the submitted data
$commentdata['comment_author_url'] = '';
return $commentdata;
}
// Hook the function to the 'preprocess_comment' filter
add_filter('preprocess_comment', 'xyzmark_remove_comment_author_url', 10, 1);
function xyzmark_remove_url($fields) {
// Check if the 'url' field exists in the $fields array and unset it if it does
if (isset($fields['url'])) {
unset($fields['url']);
}
return $fields;
}
// Hook the function to the 'comment_form_default_fields' filter
add_filter('comment_form_default_fields', 'xyzmark_remove_url');
// Additional code to remove the URL field from the HTML output
function xyzmark_remove_comment_url_input($html) {
$html = preg_replace('/<input.*?id="url".*?>/i', '', $html);
return $html;
}
// Hook the function to the 'comment_form_field_url' filter
add_filter('comment_form_field_url', 'xyzmark_remove_comment_url_input');
本文标签: How to remove website url field from comment form completely
版权声明:本文标题:How to remove website url field from comment form completely? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736687257a1947734.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论