一般的wordpress链接过滤器

时间:2014-02-25 12:25:08

标签: wordpress permalinks

大家好!我需要添加域名前缀www,而不是手写,每个过滤器为post_link,page_link,category_link等等 - 所有网址都有一个全局过滤器添加www。如何更改数据库中站点URL的常规设置或更改选项或htaccess的方法 - 只是不适合。在此先感谢您的回复。

2 个答案:

答案 0 :(得分:12)

如果您无法通过wp-admin进行更改,则可以使用以下内容:

        add_filter( 'post_link', array($this, 'changePermalinks'), 10, 3);
        add_filter( 'page_link', array($this, 'changePermalinks'), 10, 3);
        add_filter( 'post_type_link', array($this, 'changePermalinks'), 10, 3);
        add_filter( 'category_link', array($this, 'changePermalinks'), 11, 3);
        add_filter( 'tag_link', array($this, 'changePermalinks'), 10, 3);
        add_filter( 'author_link', array($this, 'changePermalinks'), 11, 3);
        add_filter( 'day_link', array($this, 'changePermalinks'), 11, 3);
        add_filter( 'month_link', array($this, 'changePermalinks'), 11, 3);
        add_filter( 'year_link', array($this, 'changePermalinks'), 11, 3);

        function changePermalinks($permalink, $post) {

                if ( strpos($permalink, '://www.') ) return $permalink;

                return str_replace('://', '://www.', $permalink);
        }

答案 1 :(得分:2)

在信息中心中转到设置 - >一般和第四和第五选项应为“WordPress地址(URL)”和“站点地址(URL)”。将http://example.com更改为http://www.example.com,它应该更改所有链接。

相关问题