Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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/?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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: http://stackoverflow.com/questions/4532508/how-to-change-the-attachment-url-in-wordpress

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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