Skip to content

Instantly share code, notes, and snippets.

@endurtech
Last active July 17, 2019 21:04
Show Gist options
  • Select an option

  • Save endurtech/0016602939d1405d6251a1bcea101a71 to your computer and use it in GitHub Desktop.

Select an option

Save endurtech/0016602939d1405d6251a1bcea101a71 to your computer and use it in GitHub Desktop.
Remove Option to Allow trackbacks and pingbacks when Editing Posts in WordPress
<?php
/*
** Disable Existing Discussion MetaBox
*/
add_action( 'admin_menu', 'remove_discussion_meta_box' );
function remove_discussion_meta_box()
{
remove_meta_box( 'commentstatusdiv', 'post', 'normal' );
}
/*
** Create New MetaBox
*/
add_action( 'add_meta_boxes', 'add_custom_discussion_meta_box' );
function add_custom_discussion_meta_box()
{
add_meta_box( 'custom_discussion', __( 'Discussion' ), 'custom_discussion_meta_box', 'post' );
}
/*
** New Discussion MetaBox Content
*/
function custom_discussion_meta_box( $post )
{
if ( $post->comment_status == "open" )
{
$discussion_comments_checked = 'checked="checked"';
}
echo '<input name="advanced_view" type="hidden" value="1" />
<p class="meta-options">
<input name="comment_status" type="checkbox" id="comment_status" value="open" '.$discussion_comments_checked.' /> <label for="comment_status" class="selectit">Allow comments</label>
<input name="ping_status" type="hidden" id="ping_status" value="' . $post->ping_status . '" />' . do_action( "post_comment_status_meta_box-options", $post ) . '
</p>';
}
?>
<?php
/*
** Remove 'Allow Trackbacks/Pingbacks' from Quick Edit
*/
add_action( 'admin_head-edit.php', 'remove_pings_quickedit' );
function remove_pings_quickedit()
{
global $current_screen;
if ( 'edit-post' != $current_screen->id )
{
return;
echo '<script>
jQuery(document).ready(function($)
{
$(\'span:contains("Allow Pings")\').each(function (i)
{
$(this).remove();
});
$(\'input[name=ping_status]\').each(function (i)
{
$(this).remove();
});
});
</script>';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment