0

For a custom role, I've to remove/hide the email and URL fields in the author box inside the Edit Comment area in WP admin. Only the name field should be visible there.

edit comments page in wp-admin

I've to keep the URL and email field enabled for comments in the discussion settings, and can't hide the fields only on the frontend using CSS. They should be removed entirely from the source code of the page, so backend code which removes the fields would be the most likely approach.

Example URL of an edit comment page in WP admin: wp-admin/comment.php?action=editcomment&c=544499.

The form comes from wp-admin/edit-form-comment.php, which is called from wp-admin/comment.php. Can anyone suggest a way to remove the 2 fields from showing up in the form? Thanks.

1 Answer 1

0

There is no filter hook to customize comment edit fields on admin page. However you can hide those two fields using CSS, add the code below on your active theme.

function wp_ste_remove_commentfields() {
    global $pagenow;
    if ( $pagenow != 'comment.php' ) return;
    ?>
    <style>
        .editcomment tr:nth-child(2),
        .editcomment tr:nth-child(3) {
            display: none;
        }
    </style>
    <?php
}
add_action( 'admin_print_styles', 'wp_ste_remove_commentfields' );
4
  • Thanks, but I'm not looking for a CSS/JS solution that would remove the fields on the frontend. Looking for PHP code that doesn't load the fields on the page.
    – sgr12
    Oct 23, 2021 at 19:40
  • @sgr12 Have you even tried to look at the code in wp-admin/comment.php? There is no filter or hook to customize those fields :), however this code will not hide the fields on the frontend, unless the fields have the same class name. Oct 25, 2021 at 0:32
  • Yes, I have looked at the code and know the limitations; it's a hard one. Know of any plugin/external code that allows customizable comment moderation for authors that bypasses the wp-admin/comment.php form?
    – sgr12
    Oct 25, 2021 at 17:31
  • Hi @sgr12 that file is part of the core, modifying the core can have all kinds of unintended consequences, like preventing updates from working correctly, further screwing up an installation. Oct 26, 2021 at 2:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.