Skip to content

Instantly share code, notes, and snippets.

@iamayaz
Last active June 13, 2016 09:06
Show Gist options
  • Save iamayaz/85aedd0b540c8e7550b23b55d8ba7b03 to your computer and use it in GitHub Desktop.
Save iamayaz/85aedd0b540c8e7550b23b55d8ba7b03 to your computer and use it in GitHub Desktop.
//In function.php
// For Rewriting the URLS in WORDPRESS
add_filter('query_vars', 'add_state_var', 0, 1);
function add_state_var($vars){
$vars[] = 'cp';
return $vars;
}
add_filter('query_vars', 'add_singled_var', 0, 1);
function add_singled_var($vars){
$vars[] = 'dcat';
return $vars;
}
//http://example.com/digital-post-page/?cp=website-development-1/ change to http://example.com/digital-post-page/website-development-1/
add_rewrite_rule('^digital-post-page/([^/]+)/?$','index.php?pagename=digital-post-page&cp=$matches[1]','top');
add_rewrite_rule('^media-post-page/([^/]+)/?$','index.php?pagename=media-post-page&cp=$matches[1]','top');
//http://example.com/why-do-you-need-one/?dcat=website-development-1 change to http://example.com/why-do-you-need-one/website-development-1
add_rewrite_rule('^/([^/]+)/?$','index.php?dcat=$matches[1]','top');
//In related page
//For getting the parameter in the page
echo get_query_var('dcat');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment