Articles of best practices

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 all seem to involve some sort of hack, a rewrite rule to fix the inevitable 404. Some […]

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’ and the taxonomy term is ‘computers’. The URL of the term’s page would now be In order to […]

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: $args=array( ‘post_parent’ => $pos_id, ); $sublabels=get_posts($args); foreach($sublabels as $sublabel) { // blabla something to do foreach} Or: query_posts(array( ‘post_parent’ => $pos_id, ‘cat’ => ‘label’, […]

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 wouldn’t want to load it more than once. How can you find out if Modernizr is already available before enqueueing it yourself? This […]

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 will be primarily used in the content area. I want to allow the user to display that content in the sidebar […]

What are the best practices for maintaining and deploying several parent themes?

I’ve been trying to commission a freelancer to make me a custom website and hit a roadblock when I said I wanted a parent theme. The freelancer strongly preferred to make a child theme based on his self-made, free go-to theme that he updated frequently. Justin Tadlock did a great writeup on Frameworks? Parent, child, […]

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 problems(performance, etc.) if I do this in a foreach loop and switch to detect what script I need? Do […]

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 few posts from my Custom Post Type. Inside my archive-myCPT.php I will have a link called let’s say “Special […]

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 calling a method) whenever the following happens: A post is published A page is published A comment is added This will […]

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 structures. Some themes place important php files in the includes folder, others in a library folder, some in a functions folder… […]