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.
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' );
}