Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

General wordpress link filter

everyone! I need to add the domain prefix www, not to write by hand, each filter as post_link, page_link, category_link and so on - there is a global filter to all urls added www. Methods of how to change the general settings in the site url in the database or change options or htaccess - just do not fit. Thanks in advance for your reply.

like image 400
SergeevDMS Avatar asked Feb 25 '14 12:02

SergeevDMS


2 Answers

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);
        }
like image 142
Mikhail Avatar answered Nov 12 '22 23:11

Mikhail


In your dashboard go to Settings -> General and the fourth and fifth option should be "WordPress Address (URL)" and "Site Address (URL)". Change the http://example.com to http://www.example.com and it should change all links.

like image 30
Howli Avatar answered Nov 12 '22 22:11

Howli