0

Currently, the media for a page on /hello-world/ is shown on /hello-world/attachment/image-name/. Is it possible to remove attachment from this URL, and make it /hello-world/image-name/?

2

Don't include %category% anywhere in your custom permalink string, then it won't need the "attachment" text. Also, don't use numeric slugs for the page/post name. Same basic problem occurs there.

| improve this answer | |
0

Try adding this code to your functions.php file as provided by TheDeadMedic:

function __filter_rewrite_rules( $rules )
{
    $_rules = array();
    foreach ( $rules as $rule => $rewrite )
        $_rules[ str_replace( 'attachment/', 'media/', $rule  ) ] = $rewrite;
    return $_rules;
}
add_filter( 'rewrite_rules_array', '__filter_rewrite_rules' );

function __filter_attachment_link( $link )
{
    return preg_replace( '#attachment/(.+)$#', 'media/$1', $link );
}
add_filter( 'attachment_link', '__filter_attachment_link' );

SOURCE: https://stackoverflow.com/questions/4532508/how-to-change-the-attachment-url-in-wordpress

| improve this answer | |

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.