【问题标题】:How to change the attachment url in Wordpress如何在 Wordpress 中更改附件 url
【发布时间】:2011-05-30 18:29:59
【问题描述】:

我正在尝试将链接更改为 Wordpress 中的主附件页面。基本上,我正在尝试将附件一词更改为媒体。

我正在尝试改变:

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

到:

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

提前感谢您对此提供的任何帮助。

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    我知道这是一个老问题,但我只是偶然发现它并认为值得一试;

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

    【讨论】:

      猜你喜欢
      • 2012-09-01
      • 2011-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-30
      • 1970-01-01
      • 2018-07-03
      • 2011-12-24
      相关资源
      最近更新 更多