开发者

How to change the attachment url in Wordpress

What I'm trying to do is change the link to the main attachment page in Wordpress. Basically, I'm trying to change the word attachment to media.

I'm trying to change:

example.com/paren开发者_开发百科t-category/child-category/post-slug/attachment/attachment-name/

to:

example.com/parent-category/child-category/post-slug/media/attachment-name/

Thanks in advance for any help on this.


I know this is an old question, but I just stumbled on it and thought it was worth a shot;

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' );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜