wordpress - Custom post Types slug and permalinks issue - SEO and Structure -


i see issue has been brought before don't seem address specific issue. feel specific issue broad 1 though. may seem paradoxical hear me out.

for site i'm working on in wordpress, created pages counties serve. far have 1 bucks, montgomery, , delaware counties, there plenty more. there want people able navigate "recent jobs" based on county client can add themselves. can 1 many jobs client wants add. these pages talk specific job in specific town, link "related jobs" job type, not county. these go 3 levels deep, county hub page > specific job in specific town > specific job type (ie: bucks county, pa > window replacement job in newtown, pa > window replacement job in wherever).

hope makes sense. did create page each county. created custom post type: county jobs. created custom taxonomies each county group them county. need taxonomies group them job type i'm not there yet. set template "single-county-job.php" , custom fields display on post type. problem came when "/county-job/", post type slug, displays in url. adding level bad seo rankings. if search in google see first pages of results show sites go 2 levels deep: "url.com/level1/level2" , "/level3/" @ best on third page (besides sites amazon or ebay). ideally want url be: "/bucks-county-pa/post-title" not "/county-job/bucks-county-pa/post-title". doesn't make sense user go "/bucks-county/" page "/county-job/bucks-county-pa/post-title".

so found multiple ways slug out of url result in 404. wordpress no longer recognizes post post. there redirect rules can add around 404s not seo either. read bad practice, hack, , shouldn't done.

have set similar pages/posts in past , how did handle it? slug problem, making cpt each county not option either because there way many , same set - doesn't make sense. maybe shouldn't cpt, how handle it? doesn't seem should pages, , how handle custom fields?

i stuck! or insight provide huge help.

considering word county static in url, can use in order make wordpress recognize you're trying request. can use generate_rewrite_rules filter in order add own rewrite rule:

add_filter('generate_rewrite_rules', 'my_rewrite', 9); function my_rewrite($wp_rewrite) {     $wp_rewrite->rules = array_merge(array(         '^([^-]*)-county-([^/]*)/([^/]*)/?$' => 'index.php?post_type=county-job&county=$matches[1]-county-$matches[2]&county-job‌​=$matches[3]'     ), $wp_rewrite->rules); } 

the second important part tell worpdress not use anymore links /county-job/ prefix. can post_type_link filter:

add_filter('post_type_link', 'my_post_link', 1, 3); add_filter('post_link', 'my_post_link', 10, 3); add_filter('page_link', 'my_post_link', 10, 3); function my_post_link($post_link, $id = 0) {   $post = get_post($id);   if(is_object($post) && $post->post_type == 'job') {       return str_replace('county-job/', '', $post_link);   }   return $post_link; } 

don't forget need flush rewrite rules in order make script working. can visiting permalinks section in wp office.


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -