开发者

How to change the attachment url in Wordpress

开发者 https://www.devze.com 2023-02-01 09:11 出处:网络
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.

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

精彩评论

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

关注公众号