Berikut adalah beberapa petunjuk dan kode yang dapat Anda gunakan untuk mengoptimalkan kecepatan situs yang dapat Anda uji di sini https://developers.google.com/speed/pagespeed/insights/?hl=en
- Pasang plugin Autoptimize dan setel opsi berikutnya:
- Pasang plugin WP Super Cache
- Pasang plugin Kompres gambar JPEG & PNG
- Tetapkan pilihan Anda di sini '/wp-admin/options-general.php?page=tinify'
- Pasang plugin Nonaktifkan Embeds
- Pasang plugin Nonaktifkan Emoji (ramah GDPR)
- Tambahkan kode berikutnya dalam file tema wordpress Anda saat ini functions.php:123456789101112131415161718192021222324add_filter('autoptimize_html_after_minify', function($content) {$site_url = 'https://YOUR_SITE_LINK_HERE';//do not set slash on the end$content = str_replace("", ' ', $content);$content = str_replace('', ' ', $content);$content = str_replace(" ", ' ', $content);$content = str_replace(' ', ' ', $content);$content = str_replace("rel='stylesheet preload' as='style'", "rel='stylesheet preload'", $content);$content = str_replace('rel="stylesheet preload" as="style"', 'rel="stylesheet preload"', $content);$content = str_replace('@font-face {font-display: swap; ', '@font-face {font-display: swap; font-display: swap;', $content);$content = str_replace('@font-face {font-display: swap; ', '@font-face {font-display: swap; font-display: swap;', $content);$content = str_replace("<img", "<img loading='lazy'", $content);$content = str_replace($site_url . '/wp-includes/js', '/wp-includes/js', $content);$content = str_replace($site_url . '/wp-content/cache/autoptimize', '/wp-content/cache/autoptimize', $content);$content = str_replace($site_url . '/wp-content/themes/', '/wp-content/themes/', $content);$content = str_replace($site_url . '/wp-content/uploads/', '/wp-content/uploads/', $content);$content = str_replace($site_url . '/wp-content/plugins/', '/wp-content/plugins/', $content);return $content;}, 9999, 1);
- Juga dimungkinkan untuk dioptimalkan jquery.js yang dikecualikan dalam Autoptimize, tetapi cara ini tidak selalu berhasil, jadi periksa fungsionalitas situs Anda setelah berikutnya:
- di file tema wp situs Anda saat ini functions.php tambahkan kode berikutnya:1234//exlude jquery to print it in the header by file_get_contentsadd_action('wp_enqueue_scripts', function () {wp_deregister_script('jquery');});
- di file tema wp situs Anda saat ini functions.php tambahkan kode berikutnya sebelumnya :123<script><?php echo file_get_contents(ABSPATH . WPINC . '/js/jquery/jquery.js'); ?></script>
- di file tema wp situs Anda saat ini functions.php tambahkan kode berikutnya:
- hati-hati jquery.js optimasi