WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is an exampple from a woothemes theme. I'm definetly not having a go at woothemes - they are a great theme provider with great standards and this sort of thing is fairly typical in themes. why?

Is this sort of code best practice in wordpress? I suppose I'm expecting view type stuff to be in a template file or partial, not in an php includes file

/* Optionally load top navigation. */

if ( ! function_exists( 'woo_top_nav' ) ) {
function woo_top_nav () {
    if ( function_exists( 'has_nav_menu' ) && has_nav_menu( 'top-menu' ) ) {
        global $woo_options;

    <div id="top">
        <div class="col-full">
            <?php superstore_contact(); ?>
            <nav role="navigation" class="top-nav">
                <?php wp_nav_menu( array( 'depth' => 6, 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'top-nav', 'menu_class' => 'nav fl', 'theme_location' => 'top-menu' ) ); ?>
    </div><!-- /#top -->

} // End woo_top_nav()
share|improve this question

I think WordPress is one of the cases where the original code just got bigger and bigger without having a chance to be rewritten from ground up with best practices.

In this case, I think the WordPress conventional practice (writing markup in function) outweigh the best practices.

You might find the theme development documentation interesting to see the rules theme authors follow to develop themes: http://codex.wordpress.org/Theme_Development

share|improve this answer
Thanks Elisha, isn't template parts where this sort of thing should go? & if not how hard would a simple template partial system be that has access to content & menu helpers? – Will May 24 '13 at 6:24
This function was referenced from the header, through two more functions and finally to this. pretty challenging for designers to work through. – Will May 24 '13 at 6:25
I think choosing a good theme to start off will help you in the designing process. Some themes are intentionally bare bone and gives lot of flexibility for you to override markup of certain parts of website via action hooks. Try 'framework' themes or developer oriented themes such as PageLines, Geneis Framework, DIYthemes, Bootstrap WP, etc – Elisha Terada May 24 '13 at 6:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.