All Questions
115,167
questions
457
votes
7
answers
191k
views
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?
346
votes
108
answers
167k
views
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
62k
views
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 ...
181
votes
5
answers
521k
views
Get WordPress post content by post id
How can I get WordPress post content by post id?
179
votes
5
answers
197k
views
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 ...
162
votes
6
answers
405k
views
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 ...
155
votes
10
answers
73k
views
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 ...
150
votes
13
answers
57k
views
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 ...
149
votes
7
answers
211k
views
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); ?>">...
145
votes
7
answers
64k
views
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?
144
votes
5
answers
134k
views
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
...
142
votes
9
answers
23k
views
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, ...
139
votes
12
answers
538k
views
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-...
138
votes
36
answers
18k
views
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
8
answers
382k
views
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 ...
135
votes
17
answers
105k
views
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 ...
134
votes
9
answers
40k
views
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 ...
129
votes
4
answers
236k
views
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?
127
votes
14
answers
547k
views
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 ...
125
votes
7
answers
106k
views
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 ...
113
votes
11
answers
47k
views
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" ...
111
votes
4
answers
111k
views
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
...
110
votes
12
answers
17k
views
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 <iframe> on every page like so:
<iframe src="http://evilsite.com/go/1">&...
108
votes
8
answers
77k
views
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 ...
108
votes
2
answers
60k
views
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 ...
108
votes
5
answers
73k
views
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 ...
106
votes
6
answers
165k
views
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
104
votes
4
answers
83k
views
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 ...
101
votes
7
answers
270k
views
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 ...
99
votes
7
answers
18k
views
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 ...
98
votes
7
answers
67k
views
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 ...
95
votes
3
answers
42k
views
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 ...
94
votes
11
answers
122k
views
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 ...
91
votes
1
answer
131k
views
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
90
votes
6
answers
151k
views
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 http://example.com/blog then site_url() returns http://example.com/blog
But then ...
85
votes
11
answers
144k
views
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", ...
85
votes
15
answers
7k
views
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.
84
votes
10
answers
66k
views
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 ...
83
votes
7
answers
184k
views
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, ...
83
votes
4
answers
117k
views
Create custom page templates with plugins?
Is it possible to make custom page templates available from a plugin?
83
votes
3
answers
28k
views
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 ...
81
votes
14
answers
147k
views
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
yourdomain.com/CPT-SLUG/post-name
are now very outdated solutions often referencing pre WP version 3.5 ...
81
votes
9
answers
149k
views
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 )...
80
votes
9
answers
179k
views
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 . '/...
78
votes
8
answers
52k
views
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 ...
78
votes
11
answers
10k
views
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
9
answers
96k
views
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-...
77
votes
13
answers
83k
views
Can I rename the wp-admin folder?
Is it possible to rename the wp-admin folder?
I know I could just rename it, but unless it's supported by the code lots of things would break.
If I use a custom folder name, it will make it slightly ...
76
votes
8
answers
66k
views
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 ...
76
votes
2
answers
185k
views
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',...