Browse Source

redirect attachment pages

windhamdavid 3 years ago
parent
commit
08b2b17739
2 changed files with 60 additions and 2 deletions
  1. 59 1
      functions.php
  2. 1 1
      style.css

+ 59 - 1
functions.php

@@ -8,4 +8,62 @@ add_action( 'wp_enqueue_scripts', 'fht_enqueue_styles' );
 function fht_fontkit_name(){ ?>
   <link rel="stylesheet" href="https://use.typekit.net/sem4mxq.css"> <?php
 };
-add_action('wp_head', 'fht_fontkit_name');
+add_action('wp_head', 'fht_fontkit_name');
+
+remove_action('wp_head', 'index_rel_link' );
+remove_action('wp_head', 'rel_canonical');
+remove_action('wp_head', 'start_post_rel_link', 10);
+remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
+remove_action('wp_head', 'wp_shortlink_wp_head', 10);
+remove_action('wp_head', 'parent_post_rel_link', 10);
+remove_action('wp_head', 'rsd_link');
+remove_action('wp_head', 'wlwmanifest_link');
+remove_action('wp_head', 'wp_generator');
+remove_action('wp_head', 'feed_links_extra', 3 );
+remove_action('wp_head', 'feed_links', 2 );
+remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);
+remove_action('wp_head', 'wp_oembed_add_host_js', 10);
+remove_action('wp_head', 'rest_output_link_wp_head', 10);
+remove_action('template_redirect', 'rest_output_link_header', 11, 0);
+
+function dw_remove_wp_ver_css_js( $src ) {
+    if ( strpos( $src, 'ver=' ) )
+        $src = remove_query_arg( 'ver', $src );
+    return $src;
+}
+add_filter( 'style_loader_src', 'dw_remove_wp_ver_css_js', 9999 );
+add_filter( 'script_loader_src', 'dw_remove_wp_ver_css_js', 9999 );
+
+add_filter( 'xmlrpc_enabled', '__return_false' );
+add_filter( 'wp_headers', 'disable_x_pingback' );
+function disable_x_pingback( $headers ) {
+  unset( $headers['X-Pingback'] );
+  return $headers;
+}
+
+function disable_emojis() {
+	remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
+	remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
+	remove_action( 'wp_print_styles', 'print_emoji_styles' );
+	remove_action( 'admin_print_styles', 'print_emoji_styles' );
+	remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
+	remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
+	remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
+	add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
+	add_filter( 'emoji_svg_url', '__return_false' );
+}
+add_action( 'init', 'disable_emojis' );
+
+function dw_redirect_attachment_page() {
+	if ( is_attachment() ) {
+		global $post;
+		if ( $post && $post->post_parent ) {
+			wp_redirect( esc_url( get_permalink( $post->post_parent ) ), 301 );
+			exit;
+		} else {
+			wp_redirect( esc_url( home_url( '/' ) ), 301 );
+			exit;
+		}
+	}
+}
+add_action( 'template_redirect', 'dw_redirect_attachment_page' );

+ 1 - 1
style.css

@@ -3,7 +3,7 @@
  Author:       David A. Windham
  Author URI:   https://davidawindham.com
  Template:     Divi
- Version:      2020.1
+ Version:      2020.10
 */
 
 /*