Under the discussion tab on the post page, there's 'allow comments' and 'allow trackbacks and pingbacks', how would I hide the option to allow pingbacks from users but still have it be on by default?


Method 1 (CSS)

You can hide it for all non-admins via CSS:

function hide_ping_track_wpse_103502() {
    if( get_post_type() === "post" ){
        if( ! current_user_can( 'manage_options' ) ){
            // only for non-admins
            echo "<style>.meta-options label[for=ping_status], #ping_status{display:none !important;} </style>";
add_action( 'admin_head-post.php', 'hide_ping_track_wpse_103502' );





Method 2 (PHP)

You can also remove the native discussion metabox and replace it with your own:

add_action( 'admin_menu', 'remove_discussion_meta_box' );
add_action( 'add_meta_boxes', 'add_custom_discussion_meta_box' );

function remove_discussion_meta_box() {
    remove_meta_box('commentstatusdiv', 'post', 'normal');

function add_custom_discussion_meta_box() {
            __( 'Custom Discussion' ),

function custom_discussion_meta_box($post) {
<input name="advanced_view" type="hidden" value="1" />
<p class="meta-options">
        <label for="comment_status" class="selectit">
            <input name="comment_status" type="checkbox" id="comment_status" 
                   value="open" <?php checked($post->comment_status, 'open'); ?> /> 
            <?php _e( 'Allow comments.' ) ?>

         <input name="ping_status" type="hidden" id="ping_status" 
                    value="<?php echo $post->ping_status;?>" />

        <?php do_action('post_comment_status_meta_box-options', $post); ?>

where the ping_status form input field is hidden with the current value.



  • I'm not sure a CSS solution is the best way to go.
    – andy
    Jun 19 '13 at 15:16
  • You could of course remove the whole discussion metabox and add your own custom metabox with the modified content.
    – birgire
    Jun 19 '13 at 15:20
  • I updated the answer with that kind of solution.
    – birgire
    Jun 19 '13 at 17:11
  • Thanks, birgire. Which method do you think is better?
    – andy
    Jun 19 '13 at 17:25
  • good question, I might go with the second method, since the CSS I provided for the attribute target on the label might not be supported by all browsers ;-)
    – birgire
    Jun 19 '13 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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