How can I change wordpress link from /example-post to /news/example-post
- User
How can I change wordpress link from /example-post to /news/example-post
- Assistant
To change the WordPress link from
/example-postto/news/example-post, you can follow these steps:- Log in to your WordPress admin dashboard.
- Go to the "Settings" menu and click on "Permalinks".
- Under the "Common Settings" section, select the "Custom Structure" option.
- In the custom structure field, you can enter
/news/%postname%/. - Save the changes.
Now, your WordPress links will be in the format
/news/example-postinstead of/example-post. Make sure to update any internal links and redirects on your website to reflect this change. - User
But then it will also apply to pages
- Assistant
If you only want to change the URL structure for posts and not for pages, you can use a plugin or manually modify the code in your WordPress theme's functions.php file. Here's how you can do it manually:
- Go to Appearance > Theme Editor in your WordPress admin dashboard.
- Open the functions.php file of your active theme.
- Add the following code snippet to the functions.php file:
phpfunction custom_post_link_structure( $permalink, $post ) { if ( $post->post_type === 'post' ) { $permalink = home_url( '/news/' . $post->post_name ); } return $permalink; } add_filter( 'post_type_link', 'custom_post_link_structure', 10, 2 ); function custom_rewrite_rules() { add_rewrite_rule('^news/([^/]+)/?$', 'index.php?name=$matches[1]', 'top'); } add_action( 'init', 'custom_rewrite_rules' );