i am building a plugin for wordpress. At first, i was accounting with the default settings, where the URL of a post would be http://localhost/worpress/?p=123, and I was asking for is_single() in the wp_footer action.
When my plugin was ready, i went to try to cleanup my code. There are (at least) two things that i’m getting wrong:
- Why does it return false, when i ask for
is_single()in theinitaction or something sooner thanwp_footer? - Why, when i try a var_dump($_REQUEST) (or _POST, or _GET) anywhere in my page cycle, i get an empty array, after switching the permalink options to url_friendly type?
Can anyone shed a light on this, please?
Question 1:
is_single()will only returntrueif you are on a single postinitaction hook occurs really early in the cycle; if you callis_singlebefore the WP_Query is instantiated you’ll get false.To figure out whether you’re calling
is_singletoo early setdefine('WP_DEBUG', true);inwp-config.php. This is on line 81 of my version of wp-config. You will see an error message from WordPress if you’re calling it too early. (Plus it’s a good tool to use during development.)Question 2:
You’re not getting
$_REQUESTparameters after switching to friendly URL’s because friendly URLs don’t have a querystring (the name/value pairs that occur after the question mark in something likehttp://localhost/worpress/?p=123.) Note thathttp://localhost/worpress/foo/bardoesn’t have a question mark.