I’ve been trying to get your code to work, but just keep coming up against a (it think small) problem:
without code (regular WordPress):
viewing an attachment page for an image goes to:
site.com/category/article-name/ATTACHMENT/image-name
… and there’s the image on the attachment page.
—————————
I’ve added a second piece of code by Milo:
function wpd_rename_attachment_rewrites( $rules ){
foreach( $rules as $key => $value ){
$new_key = str_replace( 'attachment', 'new-word', $key );
unset( $rules[ $key ] );
$rules[ $new_key ] = $value;
}
return $rules;
}
add_filter( 'rewrite_rules_array', 'wpd_rename_attachment_rewrites' );
Together, the code does 2 things: 1) change the way attachments are permalinked and 2) change the way they are reached. After adding the function and refreshing permalinks/cache:
Wiewing attachment page for an image goes to:
site.com/IMAGE/image-name
… which is nothing there because its a different URL from the correct new attachment permalink, so its an Error404 on the front end when you visit that URL.
However, you can get to the correct URL by typing in:
site.com/category/article-name/IMAGE/image-name
… and brings up the correct attachment page.
So is there a way your code can be adjusted a bit so that when you click on the attachment for an image, it goes not to site.com/IMAGE/image-name
but instead goes to site.com/category/article-name/IMAGE/image-name
(ie it adds category/article-name
to the URL direction)?
-
This reply was modified 6 years, 2 months ago by ordresser.