All Questions

Filter by
Sorted by
Tagged with
451 votes
7 answers
182k 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?
user avatar
  • 6,006
344 votes
108 answers
165k 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
61k 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 ...
user avatar
  • 3,047
176 votes
5 answers
190k 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 ...
user avatar
  • 2,053
173 votes
5 answers
488k views

Get WordPress post content by post id

How can I get WordPress post content by post id?
user avatar
  • 1,965
154 votes
5 answers
370k 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 ...
user avatar
  • 2,209
153 votes
10 answers
70k 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 ...
user avatar
  • 4,438
150 votes
13 answers
56k 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 ...
user avatar
  • 1,645
143 votes
7 answers
63k 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?
user avatar
  • 8,609
142 votes
7 answers
199k 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); ?>">...
user avatar
  • 2,829
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, ...
141 votes
5 answers
132k 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 ...
user avatar
  • 54.1k
138 votes
37 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 ...
135 votes
8 answers
353k 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 ...
user avatar
135 votes
17 answers
101k 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 ...
user avatar
132 votes
12 answers
493k 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-...
user avatar
  • 1,679
128 votes
4 answers
223k 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?
user avatar
127 votes
9 answers
38k 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 ...
user avatar
  • 2,977
120 votes
5 answers
99k 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 ...
user avatar
  • 1,483
112 votes
14 answers
458k 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 ...
user avatar
  • 1,657
112 votes
11 answers
46k 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" ...
user avatar
  • 3,326
111 votes
4 answers
109k 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 ...
user avatar
  • 4,941
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">&...
user avatar
  • 2,095
107 votes
8 answers
75k 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 ...
user avatar
107 votes
2 answers
59k 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 ...
user avatar
105 votes
6 answers
156k 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
user avatar
  • 2,798
104 votes
5 answers
69k 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 ...
user avatar
  • 1,153
104 votes
4 answers
78k 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 ...
user avatar
  • 2,813
97 votes
6 answers
17k 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 ...
user avatar
  • 105k
97 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 ...
user avatar
  • 1,185
94 votes
7 answers
249k 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 ...
user avatar
  • 3,326
93 votes
3 answers
40k 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 ...
user avatar
  • 2,710
93 votes
11 answers
121k 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 ...
user avatar
  • 97.9k
89 votes
1 answer
128k 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
user avatar
  • 2,275
86 votes
6 answers
138k 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 ...
user avatar
  • 985
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.
user avatar
82 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 ...
user avatar
81 votes
4 answers
109k views

Create custom page templates with plugins?

Is it possible to make custom page templates available from a plugin?
user avatar
  • 1,755
80 votes
10 answers
61k 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 ...
user avatar
  • 4,209
78 votes
11 answers
133k 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", ...
user avatar
  • 883
78 votes
14 answers
129k 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 ...
user avatar
  • 1,286
78 votes
9 answers
138k 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 )...
user avatar
  • 1,384
78 votes
9 answers
171k 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 . '/...
user avatar
  • 66.7k
78 votes
11 answers
9k 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 ...
76 votes
12 answers
81k 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 ...
user avatar
  • 1,040
76 votes
3 answers
53k views

When to use is_home() vs is_front_page()?

I've found that is_front_page appears to return true when I'm viewing the home page and have a single sticky post assigned there. It also returns true when I've assigned a page as the static front ...
user avatar
  • 3,115
75 votes
18 answers
6k views

WPSE Plugin Repository: The plugins that came out of WP-Answers

Link your WPSE-Plugins If you answered a question and made a plugin out of your code, than this is your place to share it. The Idea: An old comment from @MikeSchinkel during the beta phase where he ...
75 votes
27 answers
12k views

Software for WordPress Theme and Plugin Development? [closed]

What software do you use for your WordPress related needs? Please state your OS. On windows XP I use: filezilla (FTP) notepad++ (for reading of PHP / CSS files) firebug (a firefox extension to ...
74 votes
9 answers
90k 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-...
user avatar
73 votes
8 answers
48k 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 ...
user avatar

15 30 50 per page
1
2 3 4 5
2257