php - how to change url like seo friendly in wordpress
Get the solution ↓↓↓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.
Answer
Solution:
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 dashboardSettings В» 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.
Answer
Solution:
Probably you need to useadd_rewrite_tag
function, withadd_rewrite_rule
.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: composer detected issues in your platform: your composer dependencies require a php version ">= 7.3.0".
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.