I have a page with with address localhost/ . .In the navigation bar I have a new page link named Blog. SO wheni travel to that page the link is localhost/blog . Now here is my thing ...when i click on any post of that page the next page permalink become localhost/{The-post-name}. what i want is to print the link fully... like /localhost/blog/{the-post-name}. for every post i walk through this page
I have a page with with address localhost/ . .In the navigation bar I have a new page link named Blog. SO wheni travel to that page the link is localhost/blog . Now here is my thing ...when i click on any post of that page the next page permalink become localhost/{The-post-name}. what i want is to print the link fully... like /localhost/blog/{the-post-name}. for every post i walk through this page
Share Improve this question asked Feb 15, 2019 at 10:32 RITIKRITIK 1011 bronze badge2 Answers
Reset to default 0Just go to Settings > Permalinks, select Custom Structure and enter the following:
/blog/%postname%/
That will add /blog/
to the beginning of post names in their permalinks. This will not affect Pages.
You can add a rewrite rule to WordPress:
add_action( 'init', 'wpse_328813_rewrite' );
function wpse_328813_rewrite()
{
add_rewrite_rule(
'^blog/(.+)/?$',
'index.php?pagename=$matches[1]',
'top'
);
}
What that is saying is, "WordPress, when someone requests a URL with "blog", followed by a slash, and then some text, maybe followed by another slash, try to load a page matching that slug. Oh, and do this before you try any of your other rewrite rules."