Most Popular

1500 questions
139
votes
15 answers

How to get URL of current page displayed?

I want to add custom PHP code to ensure that whenever a page on my site loads in my browser, the URL of that page is echoed to the screen. I can use echo get_permalink(), but that does not work on all pages. Some pages (e.g. my homepage) display…
cag8f
  • 1,997
  • 3
  • 21
  • 31
138
votes
36 answers

Objective Best Practices for Plugin Development?

Starting a community wiki to collect up objective best practices for plugin development. This question was inspired by @EAMann's comments on wp-hackers. The idea is to collaborate on what objective best practices might be so that we can potentially…
MikeSchinkel
  • 37,600
  • 14
  • 117
  • 132
135
votes
8 answers

Updates for a private plugin?

If I write a private plugin, is there any way to use the WordPress auto-update mechanism to update it? I want to encapsulate the functionality, but it's specific to my own 5 or so blogs, so it's not a good candidate for the public plugins resource.…
artlung
  • 3,097
  • 6
  • 29
  • 37
133
votes
4 answers

How to display SQL query that ran in query?

I have come across a function before that displayed the exact SQL code that was used. In a loop for example, but can't remember. Can anybody tell me that function?
Keith
  • 1,576
  • 4
  • 17
  • 21
128
votes
7 answers

add_menu_page() with different name for first submenu item

The add_menu_page documentation says to pass the menu title as the second parameter: add_menu_page('Page Title', 'Menu Title', ...); When adding more pages later via add_submenu_page, the main page becomes the first entry in the submenu: However,…
MegaHit
  • 1,553
  • 2
  • 11
  • 12
113
votes
11 answers

Display a portion/ branch of the menu tree using wp_nav_menu()

I have a menu defined in WP Admin that looks like this: I want to be able to display all the child links on the sidebar whenever I am at a parent page. For example, if the user is on my "About Us" page, I want a list of the 4 links highlighted in…
jessegavin
  • 3,486
  • 8
  • 30
  • 26
111
votes
4 answers

Menu items description? Custom Walker for wp_nav_menu()

Normal Wordpress Menu looks like: Home | Blog | About us | Contact But I've seen many pages with descriptions under these links: Home Page | Our Blogs | About us | Contact ....meet us...| read more| basic info| contact…
Wordpressor
  • 5,051
  • 19
  • 70
  • 102
110
votes
2 answers

Uninstall, Activate, Deactivate a plugin: typical features & how-to

I'm making a WordPress plugin. What are typical things I should include in the uninstall feature? For example, should I delete any tables I created in the install function? Do I clean up my option entries? Anything else?
110
votes
12 answers

Verifying that I have fully removed a WordPress hack?

My for-fun WordPress blog at http://fakeplasticrock.com (running WordPress 3.1.1) got hacked -- it was showing an
Jeff Atwood
  • 2,095
  • 4
  • 26
  • 28
109
votes
6 answers

Using wpdb to connect to a separate database

I want to connect wpdb to another database. How do I create the instance and pass it the database name/username/password? Thanks
Wadih M.
  • 2,938
  • 3
  • 18
  • 12
109
votes
8 answers

Organizing Code in your WordPress Theme's functions.php File?

The more customization I make to WordPress the more I start thinking about if I should be organizing this file or splitting it up. More specifically, if I have a bunch of custom functions which only apply to the admin area and others which just…
NetConstructor.com
  • 4,426
  • 18
  • 70
  • 83
108
votes
5 answers

Best way to initiate a class in a WP plugin?

I've created a plugin, and of course being me, I wanted to go with a nice OO approach. Now what I've been doing is to create this class and then just below create an instance of this class: class ClassName { public function __construct(){ …
kalpaitch
  • 1,193
  • 2
  • 8
  • 8
107
votes
4 answers

How to Protect Uploads, if User is not Logged In?

I use WordPress for a private site where users upload files. I use the "Private WordPress" to prevent access in to the site if the user is not logged in. I would like to do the same to the files uploaded in the uploads folder. So if a user its not…
chifliiiii
  • 2,892
  • 4
  • 30
  • 42
104
votes
8 answers

How to check if a user is in a specific role?

I have a pretty specific requirement to show different text in a field label on the user profile page based on the current user's role. I can't seem to figure out how to check whether the current use is an "author". I am looking for a function…
jessegavin
  • 3,486
  • 8
  • 30
  • 26
100
votes
7 answers

Where to put my code: plugin or functions.php?

Is there an easy to understand scheme to decide what kind of code belongs to a plugin or the theme’s functions.php? There are many cases and many debates about that topic, mostly because there are some misconceptions about the inner workings of…
fuxia
  • 107,219
  • 39
  • 255
  • 462