All Questions

Filter by
Sorted by
Tagged with
461 votes
7 answers

When should you use WP_Query vs query_posts() vs get_posts()?

It seems like half the tutorials in the Codex and around the blogosphere use query_posts() and half use WP_Query. They all do similar things, so when should I use one over the others?
Dan Gayle's user avatar
  • 6,116
346 votes
108 answers

Best collection of code for your 'functions.php' file [closed]

As with many others who are now viewing this post, I have been reading various blogs, forums, and discussion groups to learn and improve my WordPress skills. Over the past 12 months I have been on a ...
214 votes
27 answers

How to: Easily Move a WordPress Install from Development to Production?

I do development on one box and use a second for production. Right now I just dump the database and then do a find a replace for the URL changes; then copy over the files and import the new SQL. Are ...
Ryan Gibbons's user avatar
  • 3,067
182 votes
5 answers

Get WordPress post content by post id

How can I get WordPress post content by post id?
m3tsys's user avatar
  • 2,047
179 votes
5 answers

When to use WP_query(), query_posts() and pre_get_posts

I read @nacin's You don't know Query yesterday and was sent down a bit of a querying rabbit hole. Before yesterday, I was (wrongly) using query_posts() for all my querying needs. Now I'm a little bit ...
saltcod's user avatar
  • 2,098
167 votes
6 answers

If the current user is an administrator or editor

How can I check to see if the current logged-in user is an administrator or an editor? I know how to do each individually: <?php if(current_user_can('editor')) { ?> <!-- Stuff here for ...
andy's user avatar
  • 2,359
156 votes
10 answers

Is moving wp-config outside the web root really beneficial?

One of the most common security best practices these days seems to be moving wp-config.php one directory higher than the vhost's document root. I've never really found a good explanation for that, but ...
Ian Dunn's user avatar
  • 4,837
152 votes
13 answers

Hide the fact a site is using WordPress?

I have a website for which we are trying to be discreet about the fact that we are using WordPress. What steps can we take to make it less obvious? EDIT- Important security note: Please understand ...
Casebash's user avatar
  • 1,665
150 votes
7 answers

Is it possible to get a page link from its slug?

Is it possible to get a page's permalink from the slug alone? I'm aware that you can get the page's permalink from the ID using get_page_link(): <a href="<?php echo get_page_link(40); ?>">...
Sampson's user avatar
  • 2,949
145 votes
7 answers

Disable emojicons introduced with WP 4.2

So WP 4.2 introduced emojis (smileys) that basically adds JS and other junk all over your pages. Something some people may find shocking. How does one completely erase all instances of this?
Christine Cooper's user avatar
  • 8,798
144 votes
5 answers

How to fix pagination for custom loops?

I have added a custom/secondary query to a template file/custom page template; how can I make WordPress use my custom query for pagination, instead of using the main query loop's pagination? Addendum ...
Chip Bennett's user avatar
  • 54.9k
142 votes
9 answers

Tips for using WordPress as a CMS? [closed]

I want to use WordPress as a CMS for a reasonably basic site rather than a blog. I have several pages and at the moment, I don't intend to have a "news" page. While there are ways to make this work, ...
141 votes
8 answers

How do test if a post is a custom post type?

I am looking for a way to test if a post is a custom post type. For example, in, say, the sidebar I can put in code like this: if ( is_single() ) { // Code here } I want code testing for only ...
Adam Thompson's user avatar
140 votes
12 answers

How do I retrieve the slug of the current page?

I am trying to retrieve the slug of the current WordPress page outside the loop. The title of the page returns with wp_title (), but how can I get the slug? <li> <a href="/slug-of-current-...
sarytash 's user avatar
  • 1,789
139 votes
17 answers

Adding a Taxonomy Filter to Admin List for a Custom Post Type?

I have created a Custom Post Type called 'listing' and added a Custom Taxonomy called 'businesses'. I would like to add a dropdown list of Businesses to the admin list for the Listings. Here is what ...
Taras Mankovski's user avatar
138 votes
36 answers

Objective Best Practices for Plugin Development? [closed]

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 ...
136 votes
14 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 ...
cag8f's user avatar
  • 1,937
134 votes
9 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 ...
artlung's user avatar
  • 3,077
130 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's user avatar
  • 1,546
127 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 ...
MegaHit's user avatar
  • 1,543
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" ...
jessegavin's user avatar
  • 3,456
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 ...
Wordpressor's user avatar
  • 5,041
110 votes
12 answers

Verifying that I have fully removed a WordPress hack?

My for-fun WordPress blog at (running WordPress 3.1.1) got hacked -- it was showing an <iframe> on every page like so: <iframe src="">&...
Jeff Atwood's user avatar
  • 2,095
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 ...'s user avatar
108 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 ...
redconservatory's user avatar
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 ...
kalpaitch's user avatar
  • 1,193
107 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.'s user avatar
  • 2,898
105 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 ...
chifliiiii's user avatar
  • 2,852
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 ...
jessegavin's user avatar
  • 3,456
99 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 ...
fuxia's user avatar
  • 107k
98 votes
7 answers

Get rid of Another update is currently in progress

I was trying to update my wordpress core to 4.5.1 but my system was missing some permissions, and now after giving correct permission, I cannot get rid of that message and I cannot upgrade. Tried to ...
Sam Provides's user avatar
  • 1,195
95 votes
3 answers

Between functions.php (theme), widgets, and plugins, which is loaded first?

Customer asks if a specific carousel plugin he uses can be widgetized. That means I should create a widget inside functions.php which calls the plugin's function. That means that the plugin's code has ...
pixeline's user avatar
  • 2,857
94 votes
11 answers

What are PHP extensions and libraries WP needs and/or uses?

Codex loosely only mentions PHP version in server requirements, however PHP can be configured in pretty wide range of excluding/including different parts. What are extensions/libraries that: are ...
Rarst's user avatar
  • 99.7k
91 votes
1 answer

How to edit a user profile on the front end?

How can I edit a user profile in the front end with a form? first name, last name, username, email address and password
Carson's user avatar
  • 2,345
90 votes
7 answers

What's the difference between home_url() and site_url()

My understanding is that site_url() returns the location where the WordPress core files are. If my blog is hosted at then site_url() returns But then ...
Praveen's user avatar
  • 1,025
86 votes
11 answers

Remove "Category:", "Tag:", "Author:" from the_archive_title

I have the following code in my theme's archive.php: <?php the_archive_title( '<h1 class="page-title">', '</h1>' ); ?> This gives me titles like "Category: Russia", "Tag: America", ...
Nick's user avatar
  • 963
86 votes
10 answers

Enqueue Scripts / Styles when shortcode is present

What is the idea way to register/enqueue scripts and/or styles for use in plugins? I recently made a plugin simple plugin to add the user avatar/gravatar with a shortcode. I have different style ...
Bryan Willis's user avatar
  • 4,429
85 votes
15 answers

Steps to optimize WordPress in regard to server load and website speed?

Besides installing W3 Total Cache or another caching plugin what steps can I take to make sure that my theme and site run as fast as possible.
Paul Sheldrake's user avatar
84 votes
4 answers

Create custom page templates with plugins?

Is it possible to make custom page templates available from a plugin?
jnthnclrk's user avatar
  • 1,825
83 votes
7 answers

to perform the requested action wordpress needs to access your web server. please enter your ftp

I'm following Changing File Permissions « WordPress Codex, yet when I'm try to update and/or install plugin and/or theme through wp-admin, I'm getting following: To perform the requested action, ...
alexus's user avatar
  • 930
83 votes
3 answers

Autoloading & Namespaces in WordPress Plugins & Themes: Can it Work?

Has anyone used autoloading and/or PHP namespaces within a plugin or theme? Thoughts on using them? Any harm? Pitfalls? Note: namespaces are PHP 5.3+ only. Assume, for this question, that you know ...
chrisguitarguy's user avatar
82 votes
15 answers

Remove slug from custom post type post URLs

It seems that all web resources based on the subject of removing a custom post type slug ie are now very outdated solutions often referencing pre WP version 3.5 ...
Ben Racicot's user avatar
  • 1,416
81 votes
9 answers

Get name of the current template file

I've found this to display the current name of the file used in template: function get_template_name () { foreach ( debug_backtrace() as $called_file ) { foreach ( $called_file as $index )...
chodorowicz's user avatar
  • 1,464
80 votes
8 answers

Custom Post Type Templates from Plugin Folder?

I'd like to offer my custom post type as a Plugin, so that people can use it without touching their theme folder. But custom post type templates -- such as single-movies.php -- reside in the theme ...
nathanbweb's user avatar
80 votes
9 answers

How to include PHP files in plugins the correct way

My problem is when on the main plugin file I include a PHP file something like this: include(WP_PLUGIN_URL . '/wordpress-group-buying/ipn/paypal-ipn.php'); // or include_once(WP_PLUGIN_URL . '/...
Bainternet's user avatar
  • 67.6k
78 votes
3 answers

WP_Query - Order results by meta value

I've checked around and haven't seen an answer which works as of yet. I have a WP_Query with the following arguments: $args = array( 'post_status' => 'publish', 'post_type' => 'listing',...
Adam Moss's user avatar
  • 1,052
78 votes
11 answers

WordPress frameworks and parent themes [closed]

By now there is a considerable amount of WordPress code around that is meant to be re-used by other developers. Unfortunately there is little to none practical and solid information on it and ...
77 votes
10 answers

WordPress wp-admin https redirect loop

I am using nginx as my webserver and i have edited the configuration file to point to https, so i change the WordPress url settings to https and also added the WordPress force ssl admin code to my wp-...
iamkingsleyf's user avatar
77 votes
3 answers

Counting the posts of a custom Wordpress loop (WP_Query)?

I tried tplacing this: <?php $count = count($custom_posts); ?> <h2><?php echo $count; ?></h2> at the end of the loop: <?php if ( bbp_get_forum_title() == '...
wyc's user avatar
  • 3,867
77 votes
9 answers

remove_action or remove_filter with external classes?

In a situation where a plugin has encapsulated its methods within a class and then registered a filter or action against one of those methods, how do you remove the action or the filter if you no ...
Tom Auger's user avatar
  • 7,066

15 30 50 per page
2 3 4 5