My current url is like:
abc.com/products/trade-details/?trade_name=napa
But I want this url like:
abc.com/products/trade-details/napa
How to make this in wordpress url to like seo friendly? I check many answer in stackoverflow but no one worked for me.
I tried with this on functions.php
function wpse_283774_rewrite() {
add_rewrite_rule( '^trade-details/([^/]+)/?', 'index.php?pagename=trade-details&trade_name=$matches[1]', 'top' );
}
add_action( 'init', 'wpse_283774_rewrite' );
function wpse_283774_query_vars( $vars ) {
$vars[] = 'trade_name';
return $vars;
}
add_filter( 'query_vars', 'wpse_283774_query_vars' );
but still not working.
2
Answers
Create a parent category "trade-details" and another, child category, "napa" and assign it to the forementioned category, thus you create hierarchy. Afterwards, go to a product/service you serve in Napa, at the RH sidebar of your related product editing page, choose both primary and secondary categories, first goes the parent and click to update. This has to be done on every page.
Check in your dashboard
Settings » Permalinks » Common Settings
and choose the radio buttonCustom Structure
. Change the way your WP Posts appear or, optionally, if it suits you, change the Category Base, it’s really easy! You can also install the free plugin "Yoast" on WordPress and choose the way your URLs are shown, by clicking from the left-hand menu the optionSEO » Search Appearance
and then the tabtaxonomies
. Find intaxonomies
the option "Category URLs", you can remove the categories prefix from there (Category URLs on WordPress contain a prefix, usually/category/
, this feature removes that prefix, for categories only).I do not have a clear view of your menu structure or what is shown to the end-user, so I try to guess and help as I can. It would be helpful to have the URL as a reference, it would make us understand your thought better.
Probably you need to use
add_rewrite_tag
function, withadd_rewrite_rule
.