一般的wordpress链接过滤器

Ser*_*evD 7 wordpress permalinks

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

Mik*_*ail 12

If you can't change it via the wp-admin, you can use the following:

        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);
        }
Run Code Online (Sandbox Code Playgroud)