WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sorry, this is a noob question. But, I want to follow the best practices.

I read that functions and global variables should be prefixed in plugins.

So, for example, myfunction(), should be lax_myplugin_myfunction(). And a variable, such as $myvar, should be $lax_myplugin_myvar.

Do I need to prefix a variable if it's in a function? For example,

lax_myplugin_myfunction() {

$count = 50;

return $count;


Should I prefix $count and make it $lax_myplugin_count? Or I don't have to bother with it as it's in a function. What's the best practice?

Thank you.

share|improve this question
up vote 1 down vote accepted

Functions - yes.

Class methods - no (but prefix the class name).

Variables - inside your functions/methods - no (like in your example); inside template files - yes, because there are lots of global variables exposed by WP in them, and you might get conflicts...

share|improve this answer
Thank you for the detailed answer One Trick Pony. Awesome! – Laxmidi Sep 7 '11 at 21:16
In addition to @One Trick Pony's great answer here is a link you may find useful: codex.wordpress.org/User:CharlesClarkson/Global_Variables – hsatterwhite Sep 8 '11 at 0:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.