Skip to content

Instantly share code, notes, and snippets.

@niklasravnsborg
Created January 25, 2023 16:06
Show Gist options
  • Save niklasravnsborg/decacc44180aa04bb9929d0d103aa190 to your computer and use it in GitHub Desktop.
Save niklasravnsborg/decacc44180aa04bb9929d0d103aa190 to your computer and use it in GitHub Desktop.
WP2Static Filter
<?php
add_filter('wp2static_detect_sitemaps', function() {
return false;
});
// add_filter('wp2static_detect_parent_theme', function() {
// return false;
// });
// add_filter('wp2static_detect_child_theme', function() {
// return false;
// });
// add_filter('wp2static_detect_plugin_assets', function() {
// return false;
// });
// add_filter('wp2static_detect_wpinc_assets', function() {
// return false;
// });
add_filter('wp2static_detect_vendor_cache', function() {
return false;
});
add_filter('wp2static_detect_posts_pagination', function() {
return false;
});
add_filter('wp2static_detect_archives', function() {
return false;
});
add_filter('wp2static_detect_categories', function() {
return false;
});
add_filter('wp2static_detect_category_pagination', function() {
return false;
});
add_filter('wp2static_detect_authors', function() {
return false;
});
add_filter('wp2static_detect_authors_pagination', function() {
return false;
});
add_filter('wp2static_modify_initial_crawl_list', function($urls) {
// Once we have a favicon, this can be reactivated
$urls = array_diff($urls, ['/favicon.ico']);
// Redirects for Netlify
array_push($urls, '/_redirects');
$urls = array_map(function ($url) {
if (!isset($url)) {
return;
}
// For some reason the pages / and /en/ start with http:// when returned by get_page_link().
// WP2Static than has troubles to identify them properly so we use this hack to replace the url.
$url = str_replace(
'http:/example.com/',
'/',
$url
);
return $url;
}, $urls);
$urls = array_filter($urls, function ($url) {
if (str_starts_with($url, "/wp-content/themes/stockholm/css/admin/")) {
return false;
}
if (str_starts_with($url, "/wp-content/themes/stockholm/css/img/")) {
return false;
}
if (str_starts_with($url, "/wp-content/plugins/elementor-addon-components/assets/admin/")) {
return false;
}
if (str_starts_with($url, "/wp-content/plugins/elementor-addon-components/assets/images/")) {
return false;
}
if (str_starts_with($url, "/wp-content/plugins/polylang/")) {
return false;
}
if (str_starts_with($url, "/wp-content/plugins/qi-addons-for-elementor/inc/admin/")) {
return false;
}
if (str_starts_with($url, "/wp-content/plugins/qi-addons-for-elementor/inc/blog/")) {
return false;
}
if (str_starts_with($url, "/wp-content/uploads/wpide/")) {
return false;
}
if (str_starts_with($url, "/wp-content/plugins/")) {
if (str_ends_with($url, ".png") || str_ends_with($url, ".jpg") || str_ends_with($url, ".gif")) {
return false;
}
}
return true;
});
return $urls;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment