Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter muurstickerstunter

    (@muurstickerstunter)

    Hi vickymedrano,

    The code should work, i’m going to recheck the code for you this weekend.

    You can try the following to: Open your webmaster console en go to:

    Crawl-Url Parameters. You can configure your attachment parameter up here.

    Choose edit – Select Yes …. – No Urls. You can hide your attachment content for the Google bot.

    Thread Starter muurstickerstunter

    (@muurstickerstunter)

    Hi pressword1

    We redirected all the linked-attachment urls to the parent post/pages url’s.

    All the unlinked media attachment’s are redirecting to the homepage.

    We are not using the function in de Yoast SEO plugin because is doesn’t redirect unlinked media. We wrote are own code for it in the functions.php. I wrote a (dutch) blog about the attachment url’s. If you have any questions about it let me know.

    add_action( 'template_redirect', 'attachment_redirect', 1 );
    	/**
    	 * Redirect any attachment page to their parent with 301 redirection
    	 */
    	function attachment_redirect() {
    		global $post;
    		if ( is_attachment() AND isset( $post->post_parent) AND is_numeric( $post->post_parent ) ) {
    			if( $post->post_parent !== 0 ):
    				wp_redirect( get_permalink( $post->post_parent ), 301 );
    			else:
    				wp_redirect( site_url(), 301 );
    			endif;
    			exit();
    		} elseif( isset($_GET['attachment_id']) ) {
    			wp_redirect( site_url(), 301 );
    		}
    
    	}

    Did you try using a SMTP plugin?

Viewing 3 replies - 1 through 3 (of 3 total)