Merge pull request #5095 from gregory-p/wordpress

Wordpress
This commit is contained in:
gregory-p
2021-05-20 09:24:59 +03:00
committed by GitHub

View File

@@ -59,7 +59,7 @@ function lawcarta_fonts_url() {
add_action('wp_enqueue_scripts', function () {
wp_enqueue_style('lawcarta-fonts', lawcarta_fonts_url(), array(), null);
wp_enqueue_script('custom-jquery', '//code.jquery.com/jquery-2.2.4.min.js', [], null, true);
wp_enqueue_script('custom-jquery', '//code.jquery.com/jquery-2.2.4.min.js', [], null);
wp_enqueue_style('bootstrap', '//stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', ['lawcarta-fonts'], null);
wp_enqueue_script('bootstrap', '//stackpath.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', ['custom-jquery'], null, true);
@@ -289,3 +289,69 @@ function add_custom_class($classes=array(), $menu_item=false) {
}
add_filter('nav_menu_css_class', 'add_custom_class', 100, 2);
/**
* Add Disallow for some file types.
* Add "Disallow: /wp-login.php/\n".
* Remove "Allow: /wp-admin/admin-ajax.php\n".
* Calculate and add a "Sitemap:" link.
*/
add_filter( 'robots_txt', function( $output, $public ) {
/**
* If "Search engine visibility" is disabled,
* strongly tell all robots to go away.
*/
if ( '0' == $public || LAWCARTA_ENVIRONMENT_NAME != 'prod') {
$output = "User-agent: *\nDisallow: /\nDisallow: /*\nDisallow: /*?\n";
} else {
/**
* Disallow some file types
*/
foreach( array( 'jpeg','jpg','gif','png','mp4','webm','woff','woff2','ttf','eot' ) as $ext ) {
$output .= "Disallow: /*.{$ext}$\n";
}
/**
* Get site path.
*/
$site_url = parse_url( site_url() );
$path = ( ! empty( $site_url['path'] ) ) ? $site_url['path'] : '';
/**
* Add new disallow.
*/
$output .= "Disallow: $path/wp-login.php\n";
/**
* Remove line that allows robots to access AJAX interface.
*/
$robots = preg_replace( '/Allow: [^\0\s]*\/wp-admin\/admin-ajax\.php\n/', '', $output );
/**
* If no error occurred, replace $output with modified value.
*/
if ( ! is_null( robots ) ) {
$output = $robots;
}
/**
* Remove line Sitemap.
*/
$robots = preg_replace( '/Sitemap: [^\0\s]*\n/', '', $output );
/**
* If no error occurred, replace $output with modified value.
*/
if ( ! is_null( robots ) ) {
$output = $robots;
}
/**
* Calculate and add a "Sitemap:" link.
* Modify as needed.
*/
$output .= "Sitemap: {$site_url['scheme']}://{$site_url[ 'host' ]}/wp-sitemap.xml\n";
}
return $output;
}, 99, 2 ); // Priority 99, Number of Arguments 2.