• Resolved helldog2004

    (@helldog2004)


    Good morning,

    I am trying to automatically set PDF files to noindex, because multiple people upload PDF files but don’t know how to manually set it.
    So is there some sort of code I can use in my functions.php to automatically remove the file from sitemap.xml if file is determined as a application/PDF mime?

    Thanks.

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

    (@helldog2004)

    I tried this, didn’t work out for me:

    function set_noindex_when_pdf(){
    	$supportedTypes = array( 'application/pdf' );
    	$fileType = $_FILES['type'][0];
    	$fileArray = wp_check_filetype( basename( $_FILES['name'][0] ) );
    	if( in_array( $fileArray['type'], $supportedTypes ) ) {
    		add_action( 'wpseo_saved_postdata', function() use ( $post_id ) { 
         	update_post_meta( $post_id, '_yoast_wpseo_meta-robots-noindex', '1' );
         	}, 999 );
    		}
    	}
    add_action( 'save_post', 'set_noindex_when_pdf' );
    Plugin Support Md Mazedul Islam Khan

    (@mazedulislamkhan)

    In order to better assist you, we’ll need more information.

    • Are you uploading the PDF files using the WordPress media manager?
    • Are you wanting to set noindex to the PDF files attachment pages?
    • Are you wanting to set noindex to the physical PDF files itself?

    How was it resolved? Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide PDF files from sitemap’ is closed to new replies.