WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

Well I just asking myself this, there are two ways I could implement this. What would be a better fit to coding standards? Or is this just a a matter of personal like?

And what about php and memory, assuming this would be way more complicated and executed very often. Would it cost more memory to create a function or a variable?

Solution 1:

function stuff(){


    $fluid = ( current_theme_supports('greatness') ) ? '-greatness' : '';

    $output = '<div class="box' . $fluid . '">';



Solution 2:

function stuff_alternative(){


    $output = '<div class="box' . bootgen_is_great() . '">';



function bootgen_is_great(){

    if ( current_theme_supports( 'greatness' ) )
        return '-greatness';

share|improve this question

Memory is not the issue here. There are no complex operations, and the difference will be almost unmeasurable.

What matters is readability: If your stuff function is rather short (less than eight functional steps) and you use the check just once – keep the check in it.
But if you need the support check in different functions separate it.

I'd rather optimize the names: greatness is not very descriptive, and while I like fluid layouts – they are not a synonym for great layouts. :)
Also, it is a custom name, so prefix it to avoid collisions with plugins and to tell the uninformed reader (you, one year later) that it is something custom.

Suggestion for a theme named wpse51275:

function wpse51275_box()
    // some awesome code …

    $box_class = 'box';
    current_theme_supports( 'wpse51275_fluid_layout' ) and $box_class .= '-fluid';

    $output = "<div class='$box_class'>";

    // more awesome code …
share|improve this answer
of course in this example memory is not an issue! It was a general question. Lets pretend the functions are way more complex and executed million times. I am php noob but my guess would be that a function costs more memory. – amy May 6 '12 at 13:08
And I used names like greatness only for stack overflow because its nobodys business what I am working on, of course this is not called greatness in my code. I am not familiar with this kind of and useage without any if of brackets. I don't really like it but I think its maybe a good Idea to put the whole class in a variable in the first place. – amy May 6 '12 at 13:16

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.