WordPress Plugin: Header Cleanup


Status
Not open for further replies.

Doel

Beginner 2.0
sekedar berbagi.

plugin untuk wordpress untuk membersihkan "header-header" yang tidak perlu (mis. versi wordpress, feed, dsb). silahkan dimodifikasi sesuka hati. semoga bermanfaat.

* dikumpulkan dari berbagai sumber/referensi di internet - credit goes to them... ;)

PHP:
<?php
/*
Plugin Name: WordPress Header Cleanup
Plugin URI: http://websiteanda.com
Description: Bersih-bersih WordPress
Version: 1.0
Author: Nama Anda
Author URI: http://websiteanda.com/
*/

function roots_head_cleanup() { 
    // http://wpengineer.com/1438/wordpress-header/
    remove_action( 'wp_head', 'feed_links', 2 );
    remove_action( 'wp_head', 'feed_links_extra', 3 );
    remove_action( 'wp_head', 'rsd_link' );
    remove_action( 'wp_head', 'wlwmanifest_link' );
    remove_action( 'wp_head', 'index_rel_link' );
    remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
    remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
    remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
    remove_action( 'wp_head', 'wp_generator' );
    remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
    // remove_action( 'wp_head', 'noindex', 1 );
    // add_action( 'wp_head', 'roots_noindex' );
    // remove_action( 'wp_head', 'rel_canonical' );
    // add_action( 'wp_head', 'roots_rel_canonical' );
    // add_action( 'wp_head', 'roots_remove_recent_comments_style', 1 );
    // add_filter( 'gallery_style', 'roots_gallery_style' );

    // stop Gravity Forms from outputting CSS since it's linked in header.php
    if( class_exists( 'RGForms' ) ) {
        update_option( 'rg_gforms_disable_css', 1 );
    }

    // http://wordpress.stackexchange.com/questions/5451/what-does-l10n-js-do-in-wordpress-3-1-and-how-do-i-remove-it/5484#5484
    // don't load jQuery through WordPress since it's linked in header.php
    if( !is_admin() ) {
        wp_deregister_script( 'l10n' );

        // saya lebih prefer menggunakan jquery dari google CDN (hemat bandwidth + lebih cepat)
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery', '', '', '', true );
    }
}

// mungkin kurang efektif. lebih mengena kalau di frontend (eg: varnish)
function mungil_remove_headers( $headers, $wp_query ) {
    if( isset( $headers['X-Pingback'] ) ) {
        unset( $headers['X-Pingback'] );
    }
    if( isset( $headers['X-Powered-By'] ) ) {
        unset( $headers['X-Powered-By'] );
    }
    if( isset( $headers['Pragma'] ) ) {
        unset( $headers['Pragma'] );
    }
    if( isset( $headers['Link'] ) ) {
        unset( $headers['Link'] );
    }
    return $headers;
}

add_action( 'init', 'roots_head_cleanup' );
add_filter( 'wp_headers', 'mungil_remove_headers', 100, 2 );
?>
 
Status
Not open for further replies.

Top