0

Could one please explain how can I prevent WordPress 4.9 from creating permalinks/slugs for Media files without the need of installing another plugin?

It's also important that the solution won't get overwritten by consecutive WordPress updates.

0

In a plugin or in your functions.php file put this :

if ( !function_exists( 'xxx_remove_attachment_permalink' ) ) {
    function xxx_remove_attachment_permalink( $rules ) {
        foreach ( $rules as $regex => $query ) {
            if ( strpos( $regex, 'attachment' ) || strpos( $query, 'attachment' ) ) {
                unset( $rules[ $regex ] );
            }
        }

        return $rules;
    }
    add_filter( 'rewrite_rules_array', 'xxx_remove_attachment_permalink' );
}

if ( !function_exists( 'xxx_remove_attachment_link' ) ) {
    function xxx_remove_attachment_link( $link ) {
        return;
    }
    add_filter( 'attachment_link', 'xxx_remove_attachment_link' );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.