Check if WordPress is using pretty permalinks from code

Seeing as I’ve just spent at least 10 minutes looking for this before figuring it out on my own, I figured it would be useful to have here. The issue is as follows: “How does one check if WordPress is currently using ‘pretty permalinks’ or if it’s just using a GET variable?” This issue is important for example, when you’re writing GET forms that operate on the frontend. Unfortunately, you have to add the page_id param back into the URL (usually through a hidden input), otherwise WordPress will route the query to the homepage.

Anyway, here’s the solution:

 

It’s that easy.

  • http://dwainm.com/ Dwain Lourens Maralack


    Thanks for this nice little snippet , Its a very clean solution. I use the get_permalink() function and then checked if it contained a question mark.