JB`s 개발이야기

Wordpress best practices and Tips 본문

개발언어/Wordpress

Wordpress best practices and Tips

A.K.A.캐로 2019. 5. 14. 14:44
이글은  https://www.toptal.com/wordpress/tips-and-practices 를 발췌 해석 한것 입니다. 추후에 다른 블로그에도 이런 글들이 있으면 모아서 추가할 예정입니다.

1. 캐싱속도 향상

- 워드프레스에 최적화된 Siteground 또는 더 비싼 Wpengine 과 같은 호스팅 서비스는 워드프레스 캐싱을 자동으로 지원합니다. 호스트가 워드프레스의 특정 캐싱을 사용 할 수 있는 호스트라면 최상의 선택입니다.

 루트 엑세스 권한이 있는 vps서버에서 운영되는 경우 Google Page SpeedApachenginx에서 작동하는 Googleturn key caching 및 최적화 솔루션입니다.

 이경우 CentOS환경에서 Plesk에 geSpeed(https://fabriceleven.com/dev/how-to-install-google-pagespeed-in-parallels/)를 설치 할 수 있습니다.

위의 경우가 너무 번거롭다면 무료CDN/Firewall/Caching/minification system이 있는 Cloudflare를 사용 할수 있습니다.

 

2. 보안에 주의를 기울기입시오

-암호잠금 및 파일 모니터링과 같은 보안 옵션이 있는  iTheme Security 권장 합니다그리고  Wordfence 보안  사이트에 대한 워드 프레스 특정 방화벽 등의 기능을 제공합니다.

-All In One WP Security & Firewall 추천

 

All In One WP Security & Firewall

A comprehensive, user-friendly, all in one WordPress security and firewall plugin for your site.

wordpress.org

 

3. 워드프레스 특정기능을 제거 하십시오

-워드프레스에는 설정에서 해제 할 수 없는 많은 정보들이 보여집니다. 이정보들은 워드프레스를 취약하게 만들수 있습니다.

워드프레스 버전 제거

->해커가 당신의 사이트를 더쉽게 시겨별할수 있도록 하는 워드프레스 버전 번호를 제거 하십시오functions.php 파일에 다음을 추가 하십시오.

 Add_filter(‘the_generator’, ‘__return_null’);

스크립트 버전 제거

->스크립트 다음에 버전 번호를 제거하십시오. 기본적으로 워드프레스는 모든 스크립트 버전을 추가 합니다. 이로인해 caching/minification plugins 관련 문제가 발생 있으며 해커가 사이트를 식별 할수 있습니다. 기능을 방지하려면 테마 함수 파일에 다음 코드를 추가 하십시오.

 function remove_cssjs_ver( $src ) {
		if( strpos( $src, '?ver=' ) ){
        	$src = remove_query_arg( 'ver', $src );
			return $src;
        }
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 1000 );
add_filter( 'script_loader_src', 'remove_cssjs_ver', 1000 );

 

WooCommerce 제한

-WooCommerce를 설치 한후 사이트가 느려졌습니까? 다음의 함수를 functions.php에 추가하면 WooCommerce가 아닌 페이지에서 Woocommerce 스크립트가 로드하는 것을 방지 할수 있습니다.

 /**
 * Tweak WooCommerce styles and scripts.
 * Original credit goes to Greg from: https://gist.github.com/gregrickaby/2846416
 */
function grd_woocommerce_script_cleaner() {
	
	// Remove the generator tag, to reduce WooCommerce based hacking attacks
	remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
	// Unless we're in the store, remove all the scripts and junk!
	if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
		wp_dequeue_style( 'woocommerce_frontend_styles' );
		wp_dequeue_style( 'woocommerce-general');
		wp_dequeue_style( 'woocommerce-layout' );
		wp_dequeue_style( 'woocommerce-smallscreen' );
		wp_dequeue_style( 'woocommerce_fancybox_styles' );
		wp_dequeue_style( 'woocommerce_chosen_styles' );
		wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
		wp_dequeue_style( 'select2' );
		wp_dequeue_script( 'wc-add-payment-method' );
		wp_dequeue_script( 'wc-lost-password' );
		wp_dequeue_script( 'wc_price_slider' );
		wp_dequeue_script( 'wc-single-product' );
		wp_dequeue_script( 'wc-add-to-cart' );
		wp_dequeue_script( 'wc-cart-fragments' );
		wp_dequeue_script( 'wc-credit-card-form' );
		wp_dequeue_script( 'wc-checkout' );
		wp_dequeue_script( 'wc-add-to-cart-variation' );
		wp_dequeue_script( 'wc-single-product' );
		wp_dequeue_script( 'wc-cart' ); 
		wp_dequeue_script( 'wc-chosen' );
		wp_dequeue_script( 'woocommerce' );
		wp_dequeue_script( 'prettyPhoto' );
		wp_dequeue_script( 'prettyPhoto-init' );
		wp_dequeue_script( 'jquery-blockui' );
		wp_dequeue_script( 'jquery-placeholder' );
		wp_dequeue_script( 'jquery-payment' );
		wp_dequeue_script( 'jqueryui' );
		wp_dequeue_script( 'fancybox' );
		wp_dequeue_script( 'wcqi-js' );

	}
}
add_action( 'wp_enqueue_scripts', 'grd_woocommerce_script_cleaner', 99 );

 

5.함수를 이용하여 스크립트 및 css로드

-워드프레스는 이미 로드된 모든 스크립트과 CSS를 추적하므로 js CSS를 머리말이나 꼬리말에 추가하는 대신 워드프레스의 enqueue기능으로 처리하도록 합니다.

이것으로 워드프레스는 종속성을 점검하고 잠재적인 충돌을 피할수 있습니다.

Enqueue 메소드(wp_enqueue_script()또는 wp_enqueue_style()) functions.php파일에 추가합니다. 다음은 예시입니다.

  function add_theme_scripts() {
//example script from CDN, true means our script will be in the footer.
wp_enqueue_script( 'particles', '//cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js', array(), null, true );
});

//All referred to when to load your style like: 'screen', 'print' or 'handheld.
wp_enqueue_style( 'slider', get_template_directory_uri() . '/css/slider.css',false, null,'all'); 

//this will actually execute our function above
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
  
Comments