Skip to content

Instantly share code, notes, and snippets.

@hansspiess
Last active December 14, 2017 03:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hansspiess/aa4eb4ecb749fa619a9f6f6553d4051c to your computer and use it in GitHub Desktop.
Save hansspiess/aa4eb4ecb749fa619a9f6f6553d4051c to your computer and use it in GitHub Desktop.
wordpress tweaks
<?php
// remove wp generator
// https://css-tricks.com/snippets/wordpress/remove-wp-generator-meta-tag/
remove_action('wp_head', 'wp_generator');
// disable emojis
// http://wordpress.stackexchange.com/questions/185577/disable-emojicons-introduced-with-wp-4-2
function wpt_disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
add_filter( 'tiny_mce_plugins', 'wpt_disable_emojis_tinymce' );
add_filter( 'emoji_svg_url', '__return_false' );
}
add_action( 'init', 'wpt_disable_emojis' );
function wpt_disable_emojicons_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}
// remove unwanted post types
if ( ! function_exists( 'wpt_unregister_post_type' ) ) :
function wpt_unregister_post_type() {
global $wp_post_types;
foreach ( array( 'post', 'avada_portfolio', 'avada_faq' ) as $post_type ) {
if ( isset( $wp_post_types[ $post_type ] ) ) {
unset( $wp_post_types[ $post_type ] );
}
}
}
endif;
add_action( 'init', 'wpt_unregister_post_type', 100 );
// remove unwanted taxonomies
if ( ! function_exists( 'wpt_unregister_taxonomy' ) ) :
function wpt_unregister_taxonomy() {
global $wp_taxonomies;
foreach ( array( 'comments' ) as $taxonomy ) {
if ( taxonomy_exists( $taxonomy ) ) {
unset( $wp_taxonomies[ $taxonomy ] );
};
};
}
endif;
add_action( 'init', 'wpt_unregister_taxonomy', 100 );
// disable support for comments and trackbacks in post types
function wpt_disable_comments_post_types_support() {
$post_types = get_post_types();
foreach ($post_types as $post_type) {
if(post_type_supports($post_type, 'comments')) {
remove_post_type_support($post_type, 'comments');
remove_post_type_support($post_type, 'trackbacks');
}
}
}
add_action('admin_init', 'wpt_disable_comments_post_types_support');
// disable comments completely
// https://www.dfactory.eu/turn-off-disable-comments/
// close comments on the front-end
function wpt_disable_comments_status() {
return false;
}
add_filter( 'comments_open', 'wpt_disable_comments_status', 20, 2 );
add_filter( 'pings_open', 'wpt_disable_comments_status', 20, 2 );
// hide existing comments
function wpt_disable_comments_hide_existing_comments( $comments ) {
$comments = array();
return $comments;
}
add_filter( 'comments_array', 'wpt_disable_comments_hide_existing_comments', 10, 2 );
// remove comments page in menu
function wpt_disable_comments_admin_menu() {
remove_menu_page( 'edit-comments.php' );
}
add_action( 'admin_menu', 'wpt_disable_comments_admin_menu' );
// redirect any user trying to access comments page
function wpt_disable_comments_admin_menu_redirect() {
global $pagenow;
if ( $pagenow === 'edit-comments.php' ) {
wp_redirect(admin_url()); exit;
}
}
add_action( 'admin_init', 'wpt_disable_comments_admin_menu_redirect' );
// remove comments metabox from dashboard
function wpt_disable_comments_dashboard() {
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
}
add_action( 'admin_init', 'wpt_disable_comments_dashboard' );
// remove comments links from admin bar
function wpt_disable_comments_admin_bar() {
if ( is_admin_bar_showing() ) {
remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 );
}
}
add_action( 'init', 'wpt_disable_comments_admin_bar' );
// disable admin bar in frontend for users not logged in with administrator role
function wpt_remove_admin_bar() {
if ( ! current_user_can('administrator') && !is_admin() ) {
show_admin_bar(false);
}
}
add_action('after_setup_theme', 'wpt_remove_admin_bar');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment