Skip to content

Instantly share code, notes, and snippets.

@thebigtine
Last active February 28, 2019 21:06
Show Gist options
  • Save thebigtine/8e7f83aeebcd3cb4f70a861f57695bd5 to your computer and use it in GitHub Desktop.
Save thebigtine/8e7f83aeebcd3cb4f70a861f57695bd5 to your computer and use it in GitHub Desktop.
<?
function tf_cleanup() {
// EditURI link
remove_action( 'wp_head', 'rsd_link' );
// windows live writer
remove_action( 'wp_head', 'wlwmanifest_link' );
// previous link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
// start link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
// links for adjacent posts
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
// WP version
remove_action( 'wp_head', 'wp_generator' );
//Disabl the WordPRess JSON REST API
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
// all actions related to emojis
remove_action( 'admin_print_styles', 'print_emoji_styles' );
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_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
// remove the dns-prefetch to wordpress.org
add_filter( 'emoji_svg_url', '__return_false' );
// filter to remove TinyMCE emojis
add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
// Remove jQuery Migrate
add_filter( 'wp_default_scripts', 'remove_jquery_migrate' );
// a better title
add_filter( 'wp_title', 'rw_title', 10, 3 );
// remove WP version from RSS
add_filter( 'the_generator', 'bones_rss_version' );
// remove WP version from css
add_filter( 'style_loader_src', 'bones_remove_wp_ver_css_js', 9999 );
// remove WP version from scripts
add_filter( 'script_loader_src', 'bones_remove_wp_ver_css_js', 9999 );
// remove injected CSS for recent comments widget
add_filter( 'wp_head', 'bones_remove_wp_widget_recent_comments_style', 1 );
add_action( 'wp_head', 'bones_remove_recent_comments_style', 1 );
// remove injected CSS from gallery
add_filter( 'gallery_style', 'bones_gallery_style' );
// Remove "recent comments" styles
add_action( 'widgets_init', 'remove_recent_comments_style' );
// cleaning up random code around images
add_filter( 'the_content', 'bones_filter_ptags_on_images' );
// cleaning up excerpt
add_filter( 'excerpt_more', 'bones_excerpt_more' );
// Disable oEmbed
add_action( 'init', 'disable_oembed');
}
// Disable oEmbed
function disable_oembed() {
// Remove the REST API endpoint.
remove_action('rest_api_init', 'wp_oembed_register_route');
// Turn off oEmbed auto discovery.
// Don't filter oEmbed results.
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
// Remove oEmbed discovery links.
remove_action('wp_head', 'wp_oembed_add_discovery_links');
// Remove oEmbed-specific JavaScript from the front-end and back-end.
remove_action('wp_head', 'wp_oembed_add_host_js');
}
// filter to remove TinyMCE emojis
function disable_emojicons_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}
// Remove jQuery Migrate
function remove_jquery_migrate( &$scripts) {
if(!is_admin()) {
$scripts->remove( 'jquery');
$scripts->add( 'jquery', false, array( 'jquery-core' ), '1.10.2' );
}
}
// A better title
// http://www.deluxeblogtips.com/2012/03/better-title-meta-tag.html
function rw_title( $title, $sep, $seplocation ) {
global $page, $paged;
// Don't affect in feeds.
if ( is_feed() ) return $title;
// Add the blog's name
if ( 'right' == $seplocation ) {
$title .= get_bloginfo( 'name' );
} else {
$title = get_bloginfo( 'name' ) . $title;
}
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title .= " {$sep} {$site_description}";
}
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 ) {
$title .= " {$sep} " . sprintf( __( 'Page %s', 'dbt' ), max( $paged, $page ) );
}
return $title;
}
// remove WP version from RSS
function bones_rss_version() {
return '';
}
// remove WP version from scripts
function bones_remove_wp_ver_css_js( $src ) {
if ( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
// remove injected CSS for recent comments widget
function bones_remove_wp_widget_recent_comments_style() {
if ( has_filter( 'wp_head', 'wp_widget_recent_comments_style' ) ) {
remove_filter( 'wp_head', 'wp_widget_recent_comments_style' );
}
}
// remove injected CSS from recent comments widget
function bones_remove_recent_comments_style() {
global $wp_widget_factory;
if (isset($wp_widget_factory->widgets['WP_Widget_Recent_Comments'])) {
remove_action( 'wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style') );
}
}
// remove injected CSS from gallery
function bones_gallery_style($css) {
return preg_replace( "!<style type='text/css'>(.*?)</style>!s", '', $css );
}
// Remove "recent comments" styles
function remove_recent_comments_style() {
global $wp_widget_factory;
remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
}
// remove the p from around imgs (http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/)
function bones_filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
// This removes the annoying […] to a Read More link
function bones_excerpt_more($more) {
global $post;
// edit here if you like
return '... <a class="excerpt-read-more" href="'. get_permalink( $post->ID ) . '" title="'. __( 'Read ', 'bonestheme' ) . esc_attr( get_the_title( $post->ID ) ).'">'. __( 'Read more &raquo;', 'bonestheme' ) .'</a>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment