InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Wordpress customization tutorials

  • Handle pagination in wordpress custom php code
  • How to and why disable wordpress cron
  • How to customize wordpress image alt tag
  • How to display date in wordpress pages
  • How to display wordpress page list with specific custom field value
  • How to display wordpress top level pages
  • How to hide a post from home and RSS feed in wordpress
  • How to include bootstrap javascript and css in wordpress post
  • How to include wordpress pages in archives
  • How to override priority and change frequency in Yoast xml sitemap
  • How to remove xmlrpc from wordpress headers
  • How to setup wordpress custom query params with pretty url format
  • How to show wordpress pages on front page with skip_home custom field
  • How to use google custom search for wordpress site
  • How to write custom php in wordpress
  • No frills social share links for Wordpress sites
  • Using Wordpress custom field for displaying code
  • Wordpress - add content filter after shortcode execution
  • Wordpress - customize category and tag links
  • Wordpress - customize facebook plugin opengraph meta tags
  • Wordpress - customize posts per page for tag, category and date archive pages
  • Wordpress - exclude specific posts from archive pages
  • Wordpress - get posts/pages with missing meta key
  • Wordpress - how to add filter to description meta tag
  • Wordpress - how to create custom tag cloud
  • Wordpress - how to exclude specific tag posts from a tag archive page
  • Wordpress - write custom php log to separate file
  • Wordpress how to check if a post is being viewed by admin
 
  • Home
  • > Tutorials
  • > Wordpress
  • > Wordpress customization

How to setup wordpress custom query params with pretty url format

By admin | Last updated on Mar 20, 2016

WordPress pages can handle query parameters in url in the traditional format of “key=value”. e.g. If you want to create a page to display details of a product, you can  create a page /detail/ and take a query parameter productid. So the url may look like /detail/?productid=1234.

To handle this productid in your page, you can write write a plugin with shortcode or filter with some code like:

$product = $_GET['productid'];
// ... code to look up and display (or modify content) product info

Custom query param and pretty url

If you want to create pretty url structure, the you can use wordpress endpoint and custom query parameters. For that you will have to write a plugin in wordpress. Here is the code for endpoint and custom query params.

function my_query_vars($vars) {
  $vars[] = "productid";
  return $vars;
}
add_filter('query_vars', 'my_query_vars');
function my_rewrite_endpoint(){
  // Use EP_PERMALINK | EP_PAGES for pages and posts both
  add_rewrite_endpoint( 'productid', EP_PAGES );
}
add_filter('init','my_rewrite_endpoint');

Pretty Url format

Now the new url structure will look like this:

/detail/productid/1234/

To read the custom query param productid, you can use the following code in you wordpress plugin:

$productid = get_query_var('productid')
// ... code to lookup and display (or modify content) product info

Canonical url

You may also want to consider removing canonical url for such pages if there are any. I’m using WordPress SEO plugin which also adds canonical url to all pages. Here is code snipped to remove canonical url for a page:

function my_wpseo_canonical ($canonical) {
  if (preg_match('#/detail/#i', $canonical)) {
    return false;
  }
  return $canonical;
}
add_filter( 'wpseo_canonical', 'my_wpseo_canonical');

Suggested posts:

  1. How to display date in wordpress pages
  2. How to setup MailChimp Rss email campaign
  3. Fetch wordpress rss feed as FeedBurner user agent on command line
  4. Vim – how to go back to last edited line/context
  5. Online tools to create comic strips
  6. How to ping feedburner to force update rss cache
  7. Command line – run python webserver
  8. How to add tag and category to wordpress pages
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Tutorials, Wordpress, Wordpress customization
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress