- 速いページ速度を確保する
ページの読み込み速度が速いことは、eコマースサイトにとって非常に重要です。そのため、以下の方法でページの読み込み速度を速くすることができます:
// jQueryライブラリのバージョンパラメータを削除します。
関数 remove_jquery_version_parameter( $src ) {
if ( strpos( $src, 'jquery' ) ) { 。
$src = remove_query_arg( 'ver', $src );
}
return $src.
}
add_filter( 'script_loader_src', 'remove_jquery_version_parameter' );
add_filter( 'style_loader_src', 'remove_jquery_version_parameter' );
// WordPressの絵文字スクリプトを削除する。
ファンクション 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', 'disable_emojis_tinymce' );
}
add_action( 'init', 'disable_emojis' );
function disable_emojis_tinymce( $plugins ) { {.
if ( is_array( $plugins ) ) { 。
return array_diff( $plugins, array( 'wpemoji' ) );;
} else {
array()を返す;
}
}
// HTMLの圧縮
関数compress_html( $html ) { {圧縮する
$compressed = preg_replace( '/s{2,}/', ' ', $html );
$compressed = preg_replace( '//', ", $compressed );
$compressed を返す;
}
関数 maybe_compress_html() {
if ( ! is_user_logged_in() && ! is_admin() )
ob_start( 'compress_html' ).
}
}
add_action( 'init', 'maybe_compress_html' );
- schema.orgを使用した構造化データ
schema.org構造化データを使用すると、検索エンジンがウェブサイトのコンテンツを理解しやすくなり、SEOランキングが向上します。以下は、eコマースサイトに商品の構造化データを追加するためのサンプルコードスニペットです:
関数 add_product_schema() {
if ( is_single() && 'product' == get_post_type() ) { 。
$product = wc_get_product( get_the_ID( ) );
$json_ld = array(
'@context' => 'http://schema.org'、
'@type' => 'Product'、
'name' => $product->get_name()、
'description' => $product->get_description()、
'sku' => $product->get_sku()、
'offers' => array(
'@type' => '
'Offer', 'price' => $product->get_price(), 'priceCurrency'=> get_woocommerce_currency(), 'availability' => 'http://schema.org/' . ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ), ); echo ''; } } add_action( 'wp_head', 'add_product_schema' );
- ページのタイトルと説明文を最適化する
ページのタイトルと説明文は、検索エンジンのランキングにおいて重要な要素です。WordPressでは、以下のコードスニペットでページタイトルとディスクリプションを設定することができます:
function custom_meta_title() { global $post; if ( is_front_page() ) { $title = get_bloginfo( '名前' ); } elseif ( isホーム() ) { $title = get_the_title( get_option( 'page_for_posts', true ) ); } elseif ( is_singular() ) { $title = get_the_title( $post->ID ); } elseif ( is_category() ) { $title = single_cat_title( ", false ); } elseif ( is_tag() ) { $title =single_tag_title( ", false ); } elseif ( is_author() ) { $title = get_the_author_meta( 'display_name'、$post->post_author ); } elseif ( is_search() ) { $title = '検索結果 ' . get_search_query(); } else { $title = get_bloginfo( 'name' ); } return $title; } add_filter( 'pre_get_document_title', 'custom_meta_title' ); }.
function custom_meta_description() { global $post; if ( is_singular() ) { $description = get_the_excerpt(); if ( empty( $description ) ){ $description = wp_trim_words( $post->post_content, 30 ); } } elseif ( is_category() || is_tag() ) { $description = term_description();} elseif ( is_home() || is_front_page() ) { $description = get_bloginfo( 'description' ); } else { $description = "."; } return $description; } add_filter( 'get_the_excerpt', 'custom_meta_description' ); add_filter( 'excerpt_more', '__return_false' );
- ページURLの最適化
ページのURLもSEOランキングの重要な要素です。WordPressでは、以下のコードスニペットによってページURLを最適化することができる:
function custom_permalink( $permalink, $post ) { if ( ‘product’ === $post->post_type ) { $permalink = home_url( ‘/products/’ . $post->post_name . ‘/’ ); } return $permalink; } add_filter( ‘post_type_link’, ‘custom_permalink’, 10, 2 );
上記は、eコマース用のWordPressテーマを作成する際に知っておくべきベストプラクティスとサンプルコードスニペットです。もちろん、これは氷山の一角に過ぎず、eコマースサイトに適用できる最適化は他にもたくさんあります。
function custom_rewrite_rule() { add_rewrite_rule( '^products/([^/]*)/?, 'index.php?product=$matches[1]', 'top' ); } add_action( 'init', 'custom_rewrite_rule' );
お問い合わせ |
---|
記事が読めない?無料でお答えします!個人サイト、中小企業サイトのための無料ヘルプ! |
① 電話:020-2206-9892 |
② QQ咨询:1025174874 |
三 Eメール:info@361sale.com |
④ 勤務時間:月~金、9:30~18:30、祝日休み |