Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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

2
votes
3answers
112 views

Defer Code in Widgets - Page Speed

How to UP Page Speed With Widget Defer? Is there a way to defer a widget in the footer? I have an external API in a footer widget which is slowing down my page. It is not needed until the page is ...
0
votes
0answers
30 views

Wordpress vs. best practices from webhint.io

I've recently scanned my website and some showcase websites with webhint.io* and noticed that they all do have a lot of hints in common. To give a few examples: 'content-type' header charset value ...
0
votes
0answers
24 views

Load a costum template for each product category in woocommerce

My goal is to display a different template for each product category in a woocommerce web shop, but I'm not quite sure about the best practice to accomplish this. My logic is something like: global $...
1
vote
1answer
53 views

database interactions using OOP

I'm developing wordpress plugin which store data in database. I tried to start OOP way for my plugin according to boilerplate from Best Practicies: https://github.com/DevinVinson/WordPress-Plugin-...
1
vote
0answers
50 views

WP_Object_Cache for heavy WP_Query

I am wondering what is the best way to cache a Wp_Query that can have from 10 items to 10000. I know it's a bad practice but for specific reason I have to process all this post types all together and ...
0
votes
0answers
21 views

Is there a best practice, or typical way to do AJAX updating for data on a custom admin screen or post.php?

I have a custom post type that deploys custom meta boxes on the post.php screen. add_meta_box('myMetaBox', __( 'My Box' ),array( $this,'echoMetaBox'),'MyBox', 'side', 'high'); I want to display ...
0
votes
1answer
752 views

How to log plugin errors to plugin error_log file

How can errors, specific to a given plugin, be logged to an error_log file contained within the plugin root folder itself? Examples: Syntax errors Database errors Compatibility errors PHP fatal ...
0
votes
0answers
28 views

Upgrading a wordpress site to its newest version

I maintain a website for my wife called www.delscookingtwist.com. Recently she decided to change her theme. That was big enough a change that I could not simply do it on the live version (which, ahem, ...
0
votes
0answers
19 views

Best practice to avoid less queries

I have three different taxonomies (domain/sector/profil) specific to a post type (formation) . I have to build a search engine with dropdown of each taxonomy. These dropdowns are dependent and when a ...
1
vote
1answer
38 views

Hooking into the init action will fire it too frequently?

"Note that I don't recommend hooking the add_custom_rewrite_rule into the init action as it will fire too frequently. This is just an example. A better place to apply the function would be on theme ...
1
vote
1answer
707 views

How does the $post_type global variable work?

I need to output the name of the custom post type within archive.php and single.php. I would use something like this: if ( 'staff' == get_post_type() ) { $post_type = 'staff'; } echo '<div ...
0
votes
1answer
323 views

Why use admin-ajax.php when loading pages through AJAX?

I have used this tutorial to implement ajax page transitions on my website. After looking in to some issues, I found that on most forum post people suggest to "use" admin-ajax.php. I looked into ...
0
votes
1answer
88 views

Why is it important to check for isset and is_array before checking in_array in this example?

I was in the process of building a plugin and stumbled on the page in the codex for the login_redirect filter, where I found this particular example : function my_login_redirect( $redirect_to, $...
0
votes
1answer
33 views

What is the best practice workflow for new website overhaul and keeping current SEO ranking? [closed]

I have a WordPress site that is doing well with SEO and but the theme is quite antiquated and will be completely overhauled with a new custom theme, updated plugins and new functionality. I am ...
0
votes
1answer
14 views

Customiser colour picker and best practice for updating css

In a theme where the user can choose the colour scheme from colour pickers in the customiser, what's the best practice for updating the style sheet? My current method is to hook into wp_head and ...
1
vote
1answer
156 views

Are we allowed to use the Allman (BSD) indent style when coding WordPress plugins and themes?

I am a real fan of the Allman (BSD) coding indent style. However, when i review the top rated plugins on WordPress, i am finding them using the K&R coding indent style. Is there a requirement ...
0
votes
1answer
704 views

Best way to redirect taxonomy terms to pages

I have been wondering what would be the best way to redirect taxonomy terms to pages in Wordpress. For instance - let us assume we have a taxonomy called 'product type' for a CPT called 'products'...
1
vote
1answer
53 views

Who is responsible for data sanitization in WordPress development?

I am studying how to write more secure WordPress code by implementing validation, sanitization and data escaping wherever necessary. Validation and escaping makes perfect sense, but I am a little ...
0
votes
0answers
79 views

Fastest and most efficient SQL query to check if UID exists

What's the fastest and most efficient way to check that a unique identifier exists in a database? Especially for an insanely large DB were you just want a true/false response to break when found. ...
1
vote
0answers
38 views

Is there documentation reference for forms in menu and setting pages?

Trying to stick to WordPress best practices and improving how I do plugin development I have searched through the codex and developer documentation to see if there is anything indicating what is ...
1
vote
2answers
81 views

Clearing caches on plugin uninstall

When a plugin is uninstalled, it should remove all related data from the site (or network, if on multisite). If a plugin adds tables to the database, for example, it should remove those tables from ...
1
vote
2answers
49 views

Custom plugins/Manipulated plugins: Always a terrible idea to inherit these types of WP sites that discourage updates? [closed]

So I have been working on WP sites for a little bit now and I think I'm getting to the point where I'm starting to get to a wider range of clients with unique site builds. One site I was assigned to ...
9
votes
1answer
406 views

When should you, and when should you not, use wp_list_pluck()?

While learning about metadata lazy-loading, I met these lines of code: // Don't use `wp_list_pluck()` to avoid by-reference manipulation. $comment_ids = array(); if ( is_array( $comments ) ) { ...
0
votes
1answer
529 views

Best Practice - Customise a WooCommerce+Wordpress Templates

To integrate customise HTML/CSS to Wordpress without editing default ready theme template from Wordpress Download HTML5Blank Boiler plate modify/overide boilerplate css with our customise Css Create ...
4
votes
1answer
476 views

Preferred Use of home_url()?

This isn't a problem but rather I am just curious to see how others are using this function. The codex does not really say a preferred method of use although it does provide some straight-forward ...
0
votes
1answer
38 views

Page with several user editable text content

I'm new to WP (not to making websites) and I'm trying to see which is the community approved standard way of having a page with several user editable content (text, images…). I'm thinking on pages ...
0
votes
0answers
28 views

How to allow non-coder user to enter complicated data?

There are, of course, many ways to achieve the same thing, but I would like to recieve feedback on the way I have chosen to tackle this problem (because it feels a bit old-school and I suspect there ...
1
vote
1answer
78 views

Why Does WordPress not output admin-ajax.php path by default?

It's not uncommon for WordPress sites to have 10+ instances of the admin-ajax.php path outputted to the front-end for use by plugins and themes. Does anyone know if there is a reason WordPress core ...
5
votes
3answers
1k 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 ...
20
votes
2answers
3k 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
1answer
40 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
799 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
1answer
378 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
95 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
51 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
117 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
182 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
26 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
450 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
165 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
1answer
154 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
93 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 ...
5
votes
2answers
345 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 ...
1
vote
2answers
984 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 page-...
1
vote
0answers
100 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 ...
2
votes
1answer
6k 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
64 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 ...
1
vote
2answers
888 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 ...
9
votes
3answers
2k 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
319 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 ...