| |
| <?php
|
|
|
|
|
|
|
| add_action('init', function() {
|
|
|
| remove_action('wp_head', 'print_emoji_detection_script', 7);
|
| remove_action('wp_print_styles', 'print_emoji_styles');
|
|
|
|
|
| add_filter('heartbeat_settings', function($settings) {
|
| $settings['interval'] = 30;
|
| return $settings;
|
| });
|
| });
|
|
|
|
|
| function nexsouk_strip_query_strings($src) {
|
| return remove_query_arg('ver', $src);
|
| }
|
| add_filter('script_loader_src', 'nexsouk_strip_query_strings', 15, 1);
|
| add_filter('style_loader_src', 'nexsouk_strip_query_strings', 15, 1);
|
|
|
|
|
| add_filter('the_content', function($content) {
|
| static $img_counter = 0;
|
| return preg_replace_callback('/<img(.*?)>/i', function($matches) use (&$img_counter) {
|
| $img_counter++;
|
| $img = $matches[0];
|
|
|
|
|
| if (preg_match('/src=["\']([^"\']+)["\']/', $img, $src_match)) {
|
| $src = $src_match[1];
|
| $size = @getimagesize($src);
|
| if ($size && !preg_match('/width=|height=/', $img)) {
|
| $img = str_replace('<img', '<img width="' . $size[0] . '" height="' . $size[1] . '"', $img);
|
| }
|
| }
|
|
|
| if ($img_counter === 1) {
|
| return str_replace('<img', '<img decoding="async" fetchpriority="high"', $img);
|
| }
|
| return str_replace('<img', '<img loading="lazy" decoding="async"', $img);
|
| }, $content);
|
| });
|
|
|
|
|
| add_action('wp_head', function() {
|
| if (is_singular() && has_post_thumbnail()) {
|
| $img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
|
| if ($img && isset($img[0])) {
|
| echo '<link rel="preload" as="image" href="' . esc_url($img[0]) . '" fetchpriority="high">' . "\n";
|
| }
|
| }
|
| });
|
|
|
|
|
| add_action('wp_head', function() {
|
| echo '<link rel="preconnect" href="https://fonts.googleapis.com" crossorigin>' . "\n";
|
| echo '<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>' . "\n";
|
| }, 1);
|
|
|
|
|
| add_filter('the_content', function($content) {
|
| return preg_replace_callback('/<iframe(?![^>]*title=["\'])([^>]*)>/i', function($matches) {
|
| return '<iframe title="Embedded content from external site"' . $matches[1] . '>';
|
| }, $content);
|
| });
|
|
|
|
|
| add_filter('the_content', function($content) {
|
| return preg_replace_callback('/<a\s([^>]*href=["\'][^"\']+["\'][^>]*)>\s*<\/a>/i', function($matches) {
|
| return '<a ' . $matches[1] . '><span class="sr-only">Link</span></a>';
|
| }, $content);
|
| });
|
|
|
|
|
| add_action('template_redirect', function() {
|
| ob_start(function($html) {
|
| if (is_admin()) return $html;
|
| return preg_replace('/\s+/', ' ', $html);
|
| });
|
| });
|
|
|
| |
| |
Comments