Disable authors everywhere

Disable authors everywhere

An easy way: there is an option in Yoast SEO to disable Author archives and Date-based archives. Just go to SEO > Titles & Metas > Archives > Author archives. On the same page also exists Date-based archives option.

Better way?


add_filter( 'author_link',          'disable_autor_link' );

function author_archive_redirect() {
   if( is_author() ) {
       wp_redirect( home_url(), 301 );
       exit;
   }
}

add_action( 'template_redirect', 'author_archive_redirect' );

Disable image URL’s

Explain: Disable image attachment links

First of all, there is an option in Yoast SEO that tackles this problem. By turning it on here: SEO > Advanced > Permalinks > Redirect attachment URL’s to parent post URL every image URL attached to the post will redirect to the parent post. This will surely stop indexing WordPress attachment pages.

But I’m trying something different. I simply don’t want any kind of links or permalinks to exist, ever.

Don’t mix this with Insert Media

There is a option that tackles something else that can easily confused with what we want to achieve.

Whenever we insert new image into the post, there are options in Insert Media dialog box named Attachment Display Settings with values on Alignment, Link To and Size.

All three of these can be set as an option, and it will be in effect for all newly inserted images into posts.

You change these values using hidden /wp-admin/options.php page or by using code, as explained in this article.

One way is to change template file

Templates used in rendering images are, in this order: image.php, attachment.php, etc, as explained in Codex, and as seen in this example.

More flexible is inside plugin

More flexible solution would be to do the similar task, right from code.

Solution: http://wordpress.stackexchange.com/a/25147/74876

add_action( 'template_redirect', function () {
  global $wp_query;
  if ( is_attachment() ) {

    /* Generate 404 */
    $wp_query->set_404();
    // wp_redirect( get_permalink( $wp_query->post->post_parent ), 301 );

  }
});

I analyzed possibility to somehow modify permalink structure for attachments, but coudn’t find a way to solve it; maybe it’s even impossible.

I assumed it is possible as on custom post types, something like that should be possible, by playing with rewrite array.


permalinks - Stop WordPress from reserving slugs for media items? - WordPress Development Stack Exchange

filter: attachment_link php - Remove attachment slug from url in wordpress - Stack Overflow

filter: post_type_link permalinks - How to rewrite URI of custom post type? - WordPress Development Stack Exchange Remove The Slugs from Custom Post Type URL

date 01. Jan 0001 | modified 28. May 2021
filename: Wordpress - Disable Authors & Image URLs