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.
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);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With