For best pratices please see the WordPress coding standards, to be found in the Core Contributor Handbook.

learn more… | top users | synonyms

1
vote
3answers
109 views

On which hook should I be calling register_nav_menu(s)?

I've variously seen register_nav_menus() called: on after_setup_theme on init pasted "loose" into functions.php with no apparent change in functionality. Which hook should I be using to call this ...
9
votes
2answers
129 views

Explanation of update_post_(meta/term)_cache

I was reading over some best practices from 10up and they mention setting these two flags to false in a WP_Query ( depending on what you're querying ): 'update_post_meta_cache' => false: useful ...
0
votes
0answers
12 views

Best Practice - Multiple Templates & append Posts

I'm new to Wordpress and I've Html/Js/Php Knowledge. May I know is this a correct way to develop a custom theme site? I will have multiple templates files like : home,about,contact-us templates ...
0
votes
1answer
22 views

Associating special meaning with user id 0

I'm writing a plugin that creates a custom table holding data which is linked to a user account with a user_id field. Now if that users account would be deleted for any reason I would like to set that ...
0
votes
2answers
56 views

Theme file structure best practice

I'm building a custom theme and want to have an organized file structure. Is there a standard best practice? I looked at the file structure of popular starter themes and they all use different ...
0
votes
0answers
29 views

Is it bad practice to use $_POST['post_type'] in an action hooked on save_post?

In a custom plugin I wrote an action hooked on save_post that Only needs to fire when a particular Custom Post Type is modified Sometimes uses wp_insert_post to add a post of a second Custom Post ...
0
votes
1answer
17 views

What is the proper way to embed the HTML of an external form such as payflowlink from paypal?

I've had a request to paste in the following into a donations page for a group. The trouble is that WP is (rightfully) curtailing this HTML to prevent me or anyone from doing something less than ...
1
vote
1answer
33 views

Adding functions to hooks from within a class

Below is a trimmed down version of my plugin, to keep it simple. My setup function is being called, but when I go to the login page, it's not dying like it should. I had the plugin working earlier, ...
1
vote
1answer
31 views

Plugin: register custom post types, child ready and performance best practices

I would find best practices in performance, clean code and child theme ready, for plugin that add some custom post types to my theme. What di you think about something like this? if ( ! ...
0
votes
1answer
46 views

Should I paste CDN links in a JS file or use a Bootstrap CDN plugin?

I'm new to WP development and I don't have the experience to know if I should place CDN links in a JS file and enqueue it or use a nifty plugin such as this one. What is best practice? What should I ...
0
votes
1answer
69 views

Custom Post Types and Removing Slugs - should we do it?

I've run into issues trying to remove my custom post types slugs and I've read other questions on here from people with the same problem. We don't want that slug in our URL! But the solutions to this ...
0
votes
0answers
22 views

Registering an optional custom post type from a plugin

I see the codex notes to call flush_rewrite_rules() on plugin activation and deactivation when registering a custom post type from a plugin but I'm looking for the best practice if a plugin gives ...
0
votes
1answer
104 views

Why user_pass column in wp_users table is varchar(64)

while working on a project, I found that "user_pass" column in "wp_users" table is varchar(64). WordPress always stores user password in md5 which is a 32 char ASCII string. So why not store it in ...
1
vote
2answers
52 views

Should non-WordPress data get its own DB?

I couldn't find anything on Google or on here about best practice for data that is not really Wordpress related. Say we have a database of clients that we'll be accessing through PHP/SQL. Should I ...
0
votes
0answers
26 views

Strategies for a plugin to support CDN-enabled WordPress sites

I'm writing a plugin to manage favicons. Basically it: Store image files under wp-content/upload. Inject HTML in page headers with the URL of the images. I would like to support WordPress sites ...
0
votes
1answer
50 views

Best Method to Switch Between Terms (Custom Taxonomy)

Looking to learn something, here. With the following code, I am loading an external file for each condition based on a known set of custom terms. I'm using has_terms to check for a specific value ...
0
votes
0answers
64 views

Best practice: What belongs in theme and what in plugin for large eCommerce website

I am about to create a large custom eCommerce website that does not fit within WooCommerce. (Most of the times I use WooCommerce for eCommerce.) It has also a completely custom design. However I know ...
0
votes
0answers
54 views

Trouble Dynamically Generating XML

I am trying to dynamically build a krpano viewer, the XML is output through a function where I grab stuff like hotspots from the database. I am trying to output the XML from a function, but since I am ...
5
votes
2answers
253 views

Using filters and actions for plugin API?

I want to integrate a public API to a plugin that I develop. The usual way other plugins integrate APIs is to define some functions that can be called by any theme or plugin. However, I think this ...
0
votes
2answers
87 views

Custom templates vs page-slug

I've currently been using the slug to set the page template, using the normal hierarchy For example, if I wanted to change the page template for http://www.example.com/about-us, I would edit ...
1
vote
0answers
78 views

Best Practices for a Completely Customizable Homepage - without plugins

Let's say you have a homepage where you want to be able to feature 10 posts of various types (posts, pages, and Custom Post Types). You have hundreds of these posts to choose from. What would be the ...
0
votes
1answer
610 views

Can a plugin add to header/footer/body content?

I am just wrapping up my first WordPress plugin and the last thing I would like to do is take a piece of data that the plugin knows about (from wp_options table) and display it in either the header or ...
0
votes
1answer
40 views

Plugin Development - Functions or Hooks?

I am brand new to WordPress plugin development and have a few questions, mostly about best practices but also some specifics. Essentially I just want to trigger an action (invoking a PHP class and ...
0
votes
2answers
197 views

Using Sessions to Filter Posts - bad thing?

I have a post type archive with filtering in a sidebar and pagination at the bottom. One of my biggest problems is that I'll always lose any $_POST filtering whenever I click pagination as the page ...
4
votes
2answers
196 views

How to make a text with hyperlink translatable in WordPress?

I've seen different ways of doing making a text with a hyperlink translatable. However, I have been unable to find a single best practice. So, some of the solutions I found: // METHOD 1 sprintf( __( ...
-2
votes
1answer
115 views

When is it OK to create a custom table for a plugin? [duplicate]

A while ago I wrote a question asking about storing easily queryable data associated with a given attachment. The recommendation that I received at the time was that I should avoid using the WP ...
4
votes
1answer
130 views

Dealing with Many Meta Values, 30+

I have a "Listing" post type with 30+ meta keys which I feel like can cause a strain on the database when there's 100+ posts. Usually what I do is save each meta value 1 by 1 like so: ...
0
votes
1answer
342 views

Set cookie for visitor

I'm writing a new plugin that will allow visitor to vote. After a visitor rated a post, I'd like to block double voting. I think the better way to do it is using cookie, but of course I can't insert ...
-1
votes
1answer
39 views

Best practice to create required pages

Some times, when we work on custom wordpress themes, we need required pages. For example - custom login page. Some times, when user change slug, page template or something else - it a very difficult ...
5
votes
2answers
1k views

Creating Ajax backend for Specialised Page Template? Should admin-ajax.php be used?

We're scoping an upcoming project that will require the development of a large php web application within an existing wordpress site - this is for our use only and we've no intention of trying to ...
6
votes
1answer
476 views

Why doesn't WP_Image_Editor save images using the Filesystem API?

I was in the process checking some of my existing plugins for any unsafe filesystem accesses, when I ran across WP_Image_Editor's save function, which calls _save, which finally calls make_image ...
1
vote
1answer
726 views

Default value for add_settings_field

I'm creating a simple settings page by following these instructions. Since this is a custom plugin, I'd like one of my settings to start with a predefined value (that can later be changed). What is ...
0
votes
2answers
740 views

Install Wordpress on my VPS (Virtual Private Server)

Initial Research I have done: I know I need to have a database running with a section for WordPress. I found something called WebPI that I believe will make installation relatively simple, but I'm ...
-2
votes
1answer
117 views

Why haven't I see plugins using get_file_data to handle retrieving plugin version?

In terms of best practices, I'm curious as to why I haven't seen anyone using get_file_data or get_plugin_data to handle getting a plugin version (for versioning CSS/JS files). Many quality plugins do ...
7
votes
2answers
179 views

What is right way to go about adding functionality to a published WordPress plugin?

So I looked all over to try and find some kind of rules, or at least some common-courtesy guidelines, concerning this issue and couldn't find anything. Essentially I'm wondering what I should do when ...
19
votes
8answers
3k views

What is your best practice to execute one-time scripts?

The Problem We all have been in a situation like this, and a lot of questions on this site need a solution like this. You either have to update a database, insert a lot of data automatically, convert ...
0
votes
1answer
244 views

Is it advisable to use `add_rewrite_rule()` to serve a custom page?

I have a page called "dynamic" that's not stored in the post table at all (not a post, page or custom post type of any sort); the reason being is all the data is completely dynamic based on $_GET ...
0
votes
0answers
59 views

“Static” pages within a theme

What I want to achieve is to add vCards to my contact pages, created on the fly and downloadable. I guess I could make a very bare template with the functionality and the correct mime-settings to the ...
0
votes
2answers
861 views

Assign Page Template Within A Custom Post Type

I have registered a Custom Post Type and created a file called archive-myCPT.php and another one for single posts called single-myCPT.php. What I want to do is to create a page where I will show just ...
2
votes
1answer
591 views

CMS: Making complex pages editable by the end user

I have been tasked with re-creating a small-ish corporate Web site (maybe a dozen static pages and a blog section) using WordPress. I have no troubles with the actual Web design, nor with the PHP ...
0
votes
1answer
231 views

restore_current_blog() vs. multiple switch_to_blog() followed by removing $GLOBALS['_wp_switched_stack']

Related to this answer, which states After every instance of switch_to_blog() you need to call restore_current_blog() otherwise WP will think it is in a "switched" mode and can potentially return ...
0
votes
1answer
501 views

How long is “as long as possible” in wp_cache_set()?

The documentation for wp_cache_set() says that if you pass in 0 for $expire (which is also the default), then it is cached for "as long as possible". How long is this? What determines it? Are we ...
7
votes
2answers
712 views

Wordpress and event-driven programming - what is it about?

I want to state very clearly that this does not intend to revive the discussion about functional/procedural programming versus object-oriented programming. There is plenty said about that, on WPSE and ...
0
votes
1answer
50 views

Enqueue scripts based on options

What is the best method to enqueue scripts based on options I have? Let's say I have 50 options and for each I need to enqueue a script(some of them might repeat.). Can I have any ...
1
vote
2answers
936 views

How to optimize multiple WP_Query() calls on one page?

The current site I'm building has a homepage that is going to have around 10 instances of WP_Query(). Some of them are going to pull a series of posts, while others are targeted at one single post ...
2
votes
1answer
85 views

Naming script handles right way

I was wondering is there any convention or what is the right way for naming handles in wp_register_script() and wp_register_style() functions? For example if I am developing a plugin that uses ...
4
votes
4answers
2k views

Should I delete the default themes?

when managing a Wordpress site it gives me great pleasure to see nothing needs updating. Should I delete the default themes or is it best to leave them there? By default themes I mean: Twenty Eleven ...
0
votes
1answer
90 views

Best Way to Add UnEditable HTML to Posts

I find myself more and more needing to use tables or divs inside my wordpress posts content. The problem I find with this is that one wrong backspace or newline, copy / paste has the possibility to ...
3
votes
1answer
275 views

How can I import a class privately into a plugin?

I've written a Wordpress plugin that makes use of a simple controller/templating library I have authored, to separate out business logic from presentation. I have a (slightly theoretical) query about ...
2
votes
1answer
161 views

Is there an action/filter called when WP_Query->query is finished and assigns posts

I took a look at the WP_Query->get_posts() function and couldn't see any action/filter that is called AFTER a query finishes. I want to be able to manipulate the results once they are sent, rather ...