Beschleunigung von WordPress

Um ein möglichst schnelles öffnen einer Website zu erreichen, kann man sowohl in der htacces als auch in der functions.php einige Veränderungen vornehmen.

Optimiert die .htacceess

Folgenden Code via FTP in die .htaccess einfügen

Hier gibt´s noch mehr Infos

.htaccess zum kopieren

 # http zu https weiterleiten
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

# Browser Caching
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access 5 seconds"
  ExpiresByType image/jpg "access 1 month"
  ExpiresByType image/jpeg "access 1 month"
  ExpiresByType image/gif "access 1 month"
  ExpiresByType image/png "access 1 month"
  ExpiresByType image/ico "access 1 month"
  ExpiresByType image/x-icon "access 1 month"
  ExpiresByType text/css "access plus 1 day"
  ExpiresByType text/javascript "access 1 month"
  ExpiresByType application/javascript "access 1 month"
  ExpiresByType application/x-javascript "access 1 month"
  ExpiresByType application/x-shockwave-flash "access 1 month"
</IfModule>

# Alternatives Caching
<IfModule mod_headers.c>
  Header append Cache-Control "public"
  Header append Vary Accept-Encoding
  Header set Connection keep-alive
  Header unset ETag
  FileETag None
</IfModule>

# gzip Komprimierung
<IfModule mod_deflate.c>
  SetOutputFilter DEFLATE
</IfModule>

# Kein Zugriff auf install.php
<files install.php>
  Order allow,deny
  Deny from all
</files>

# Kein Zugriff auf wp-config.php 
<files wp-config.php>
  Order allow,deny
  Deny from all
</files>

# Kein Zugriff auf .htaccess und .htpasswd
<FilesMatch "(\.htaccess|\.htpasswd)">
  Order deny,allow
  Deny from all
</FilesMatch>

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Anleitung

Die optimierte htaccess herunterladen, mit einem Texteditor öffnen, den Inhalt kopieren und den gesamten Inhalt der original htaccess ersetzen. (Stand September 2022)

Folgenden Code in die functions.php des Child Themes einfügen

Verhindert das Laden von Google-fonts während des Öffnens der Seite

functions.php

// SWAP IMAGE modified font-swapper //
add_action( 'init', function () {
remove_action( 'wp_enqueue_scripts', 'et_builder_preprint_font' );
});
function et_builder_preprint_font_replacement() {
// Return if this is not a post or a page
if ( ! is_singular() || ! et_core_use_google_fonts() ) {
return;
}
$post_id = get_the_ID();
$post_fonts_data = get_post_meta( $post_id, 'et_enqueued_post_fonts', true );
if ( ! is_array( $post_fonts_data ) || ! isset( $post_fonts_data['family'], $post_fonts_data['subset'] ) ) {
return;
}
$fonts = $post_fonts_data[ 'family'];
if ( ! $fonts ) {
return;
}
$unique_subsets = $post_fonts_data[ 'subset'];
$protocol = is_ssl() ? 'https' : 'http';
wp_enqueue_style( 'et-builder-googlefonts-cached', esc_url( add_query_arg( array(
'family' => implode( '|', $fonts ) ,
'subset' => implode( ',', $unique_subsets ),
'display' => 'swap',
), "$protocol://fonts.googleapis.com/css" ) ) );
}
add_action( 'wp_enqueue_scripts', 'et_builder_preprint_font_replacement', 10, 2 );
// ENDE //

Folgenden Code in die functions.php des Child Themes einfügen

Verhindert die Verknüpfung zu Videohostern währen des Seitenaufbaus.

functions.php

// Remove Query Strings from enqueue scripts
add_filter( 'style_loader_src', 'remove_query_string' );
add_filter( 'script_loader_src', 'remove_query_string' );
function remove_query_string( $url )
{
    return remove_query_arg( 'ver', $url );
}
DSGVO Cookie Consent mit Real Cookie Banner