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

learn more… | top users | synonyms

7
votes
1answer
9k views

get_template_directory() vs bloginfo( 'template_directory' ) vs TEMPLATEPATH

I was reading this article: Common WordPress Development Mistakes and How to Fix Them, and in it, they author says: Getting the theme location: If you are using TEMPLATEPATH or bloginfo( ...
1
vote
2answers
114 views

Failed to invoke other hook from the init hook

Related to this question (Use wp init hook to call other hooks?) but not the same. Sometimes, I found that the hook will failed to run when I place inside the init hook, e.g. Not Work: ...
1
vote
1answer
42 views

Where to store the name of a custom table?

I'm extending the $wpdb object with properties for my custom tables. function setup_wpdb() { global $wpdb; // Create properties for custom tables $wpdb->my_plugin_table1 = ...
0
votes
1answer
65 views

If I want social media icons that link to my site's corresponding accounts, is that better to do with a plugin, or manually?

I feel like it's simple enough that coding it in would be beneficial, but I'm not sure.
1
vote
3answers
68 views

Does all editing of Wordpress occur within the dashboard, or can we use our own text editor?

I've recently ventured into the world of CMS, and I'm used to editing everything by hand with an editor like Sublime Text 2, my personal favorite. Do we do this in Wordpress, if I wanted to customize ...
7
votes
1answer
166 views

Shared functionality in plugins and themes

I recently started to develop plugins and themes and I found that I need to use several functions of on both. Sometime I think about to check if function / class exist before declared as said on this ...
8
votes
2answers
5k views

Use wp init hook to call other hooks?

I want to know if it is a good practice according to WordPress theme or plugin development. add_action('init','all_my_hooks'); function all_my_hooks(){ // some initialization stuff here and then ...
2
votes
2answers
2k views

add_action(), add_filter() before or after function.

When looking through Wordpress snippets/tutorials/plugins I often see add_action() and add_filter() being placed before the function is declared: add_action('publish_post', 'email_friends'); ...
0
votes
1answer
223 views

Create Widget or Enable Shortcodes in Sidebar

I'm well aware that WordPress by default does not process shortcodes in the sidebar. My question is why. I'm building a very small plugin that exports some content when the shortcode is present. This ...
2
votes
1answer
66 views

Use safety filters even if after applied intval?

I have some values to save into postmeta and usermeta table. Before save, I already done this: $value = intval($value) . I think this is enough. But I see some plugins still use filters on those ...
14
votes
2answers
605 views

In Which Contexts are Plugins Responsible for Data Validation/Sanitization?

I want to make sure all of the data in my plugins/themes is handled securely before entering the database and before being output to the browser. My problem is that there are situations where the API ...
10
votes
6answers
2k views

How to benchmark a WordPress installation?

I'm trying to gather some benchmarking data to determine how well my optimizations to WordPress are fairing. I've found this page on High Traffic Tips but it doesn't contain any data. Are there any ...
5
votes
3answers
627 views

Using Images in Wordpress - Best Practices

I'm not a novice to Wordpress Theme Design & Development. I've actually been doing it for a few years now and in recent years, it has become more than a hobby and is slowing shaping into a career ...
1
vote
1answer
383 views

Exposing data using a custom Wordpress API

I'm attempting to create an API through Wordpress exposing some of my back-end data. I've come to the conclusion that I cannot have a stand alone page (plugin) exposing this data because Wordpress is ...
0
votes
3answers
2k views

Loading Modernizr (or other JavaScript libraries) for use in a plugin

Download a copy of Modernizr, put it in your plugin’s directory and simply enqueue the script whenever needed. Done. The problem is that Modernizr may already be loaded by another plugin. You ...
1
vote
5answers
11k views

WordPress product catalog site [closed]

I need to create an e-commerce site with WordPress, but not 100% e-commerce. It is just a catalog site without shopping cart. Users can see various products on the site, for example, car showcase ...
64
votes
8answers
22k 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 ...
3
votes
1answer
126 views

Hyphens vs. periods in the script slug in wp_register_script?

I have seen script and style handles written in two different ways in wp_register_script and wp_enqueue_script (the same applies to wp_register_style and wp_enqueue_style): wp_register_script( ...
0
votes
1answer
317 views

Pros and Cons of Post Types vs. Multiple Blogs

I currently have 3 WordPress instances. One is primarily a coding blog (with samples/tips, and a few personal insights). One is a photo blog. One is a general quote type blog, small snippets of text ...
32
votes
3answers
2k views

How to remove a filter that is an anonymous object?

In my functions.php file I would like to remove the below filter, but I'm not sure how to do it since it's in a class. What should remove_filter() look like? add_filter('comments_array',array( ...
1
vote
2answers
152 views

How should I store global information such as a phone number so that it is editable through the CMS?

Right now I have a p element in header.php containing the address and phone number my client wishes to use for contact info. How can I set this up so that it is editable through the WP admin area so ...
0
votes
2answers
75 views

How to customize and keep things up-to-date?

I made a few websites in WP (that was kind of my first serious web-related work where I started learning about more serious and concrete stuff other than homework type of programming exercises) and ...
2
votes
1answer
605 views

Best practices: Custom theme sidebar menu - hardcode or widget?

Is it best to hardcode a sidebar menu using functions.php or sidebar.php OR use the custom menu widget? Are there times when each is appropriate?
6
votes
2answers
690 views

What are the ADVANTAGES of ORIGINAL wordpress template structure?

Precondition: coming from a Custom PHP applications(using symfony, zend and so on) world, for me it feels unnatural to have template separated in a way that is done in original wordpress theme. e.g ...
4
votes
1answer
1k views

Best practices - Should I create a child theme vs. customizing a framework theme? (such as HTML5 reset)

I have built quite a number of wordpress sites and have worked frequently with the HTML5 reset theme. My workflow has been to simply edit the files in the theme because I often use quite a bit of ...
1
vote
1answer
102 views

Customizing page content layout

For a while now I have been building WordPress based sites for clients. These sites tend to be brochure sites so feature a collection of pages all with slightly different layouts within an ...
1
vote
3answers
943 views

What is the best way to handle multiple calls to get_template_directory_uri() and similar functions?

Edit: Thanks for your replies, guys. This is exactly what I was after. You each brought up some good points. I think I'll stick with using constants. This is really a best practices/performance ...
4
votes
3answers
973 views

Best Way to Create a List of Musician Gigs in WordPress

I am currently designing a musician's wordpress theme, and am looking to create a user-controlled dynamic gig list. I've done this before using PHP, but am wondering what the best way to do it in ...
9
votes
2answers
324 views

Plugin SVN & update API - how are plugins identified?

One thing that's never been clear to me (especially since I haven't submitted a plugin to the repository) is how a plugin's unique "ID" (slug) is generated (i.e. this list). Is it a choice by the ...
4
votes
3answers
239 views

Fallback when Transient API fails

I'm trying to figure out how to best solve an issue I have with 3rd party API's (OG, Foursquare, Yelp, etc.). I use the transient API to call and store the various data in order to: Not exceed any ...
1
vote
1answer
265 views

Is it recommended to pass some data to scripts in `wp_enqueue_scripts`?

I have on many occasions used wp_enqueue_script to pass some 'query variables' to scripts like this: function my_enqueue_scripts(){ $tempurl = urlencode( get_bloginfo( 'template_url' ) ); ...
0
votes
1answer
222 views

What are “best practices” for wp-config.php

Just started reading Professional WordPress®: Design and Development I'm reading the section on "Advanced wp-config Options". I see many options which I think are pretty cool/useful, but before I ...
3
votes
2answers
109 views

Which to use to execute code during the saving of a plugin settings page?

I'm writing a plugin with a settings/option page and I want some php code to be executed whenever someone saves the settings on that page and that page alone. Which actions do I need to hook into to ...
2
votes
1answer
396 views

Recommend a guide to catching plugin errors, please?

I'm working on a small plugin and on some WP installations it throws up the white screen of death. I'm new to this, and would like to know if there is a decent guide out to there (so far my googling ...
0
votes
1answer
2k views

When to use Wordpress loop or Foreach loop?

Under what circumstances would you, (should you?) use a foreach loop, instead of the wordpress loop. I have no real coding need, but I'm curious. What's good practice here? Should I: ...
0
votes
2answers
130 views

Tips for managing code when developing a parent theme framework

I have started work on an open source theme framework that pulls in lots of great code & resources from elsewhere. For example it uses: jQuery Option Framework Theme LESS etc etc. Most of ...
1
vote
2answers
232 views

Applying OO patterns and principles to plugin development

I'm busy writing my first plugin, using PHP 5.3.5. I come from a C# environment, and I must say I'm more than happy with the level of support for good, solid OOP techniques in PHP. However, I'm a ...
5
votes
4answers
2k views

Where to put third party PHP library?

I'm developing a couple of open-source plugins and a theme (all part of a "suite") that all use the same third party PHP library. I'm wondering what is the best way to include it in Wordpress. Here ...
9
votes
1answer
2k views

Using classes instead of global functions in functions.php

In many themes I've seen (including TwentyEleven) and in the examples I've found online, when building the functions.php file for a theme all functionality is declared in a global scope. To clarify, ...
1
vote
1answer
296 views

Limitations when modifying wp_title with a filter

When constructing the HTML <title> attribute in a theme, I found there is a convenient hook for modifying wp_title. However, a quick review of themes indicates using this hook is not common ...
4
votes
2answers
1k views

Remove before_widget / after_widget content from Wp_Widget_Text

I want to take the text widget and remove the preceding / trailing markup from the text output currently showing as <div class="textwidget">Test</div> The before_widget / after_widget ...
4
votes
2answers
535 views

Loop.php vs looping inside template file

What is best practice for WP with regard to using loop.php (loop-single.php, etc) versus looping inside the template file? Does it matter with regard to efficiency or ?
12
votes
1answer
12k views

numberposts? showposts? posts_per_page?

So the documentation on the Codex is pretty clear that showposts is deprecated. But that same documentation mentions nothing of numberposts. Instead, posts_per_page is listed. But if we turn to the ...
1
vote
1answer
68 views

How would I go about creating a user ranked post popularity page?

I currently run a music blog using Wordpress as my CMS and i'm looking to redesign the site in the very near future. Part of my plan for the redesign is to try and integrate a user ranking system for ...
2
votes
1answer
570 views

When to check if a function exists

I've just started developing a WP plugin, and i've been reading some code from other plugins as a way to get started. I've seen a couple of plugins that wrap all or some of their functions in the ...
0
votes
2answers
177 views

separate posts to have (kind of) 2 blogs?

Before putting a lot of effort in this, just to find out it's not possible: Let's say I have two different categories and I want the user to be locked in one of them after choosing it from a ...
1
vote
1answer
146 views

What can I expect when moving from a hosted (WordPress.com) blog to one hosted by Page.ly

As I mentioned here, I'm planning to moving my blog to a new hosting provider from WordPress.com. I think I've settled on Page.ly as the new home for it, and I was hoping to get the benefit of ...
4
votes
3answers
375 views

Editing Complex Pages in Visual Mode

This might be a stupid question, and maybe I've missed some best practices thing, but I've been having this problem with clients using sites on WordPress. Let's say we have a fairly complex page that ...
1
vote
3answers
479 views

will post_id ever change? Can I safely use post_id for custom queries?

What are the best practices for using post_id? Can I use this safely in my templates to call specific posts, or will these post_id's ever change? The reason I ask is that randomly today the ...
9
votes
1answer
4k views

Plugin Form Submission Best Practice

I have done a lot of researching and haven't found quite what I am looking for, so I am hoping that I can be pointed in the right direction. I am developing an Events plugin that will book a ticket ...