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

I'm learning about shortcodes. My shortcode is working fine. But, I'm not getting the default values for the attributes.

function csf_cap_databaseinfo($atts,$content=null) {
    global $wpdb;

    shortcode_atts( array('title'=>'My Default', 'year'=>'1900'), $atts); 

    $greeting = $wpdb->get_results($wpdb->prepare("SELECT * FROM wp_test;")); 

     $out = '<h3>'.$atts['title'].'</h3> <h3>'.$atts['year'].'</h3><table>
                        <th style="border:1px solid #e7e7e7; padding:10px; text-align:center">ID</th>
                        <th style="border:1px solid #e7e7e7; padding:10px; text-align:center">Greeting</th>

    foreach ($greeting as $greet)
        $out .= '<tr><td style="border:1px solid #e7e7e7; padding:10px; text-align:center">'. $greet->id .'</td>'; 
        $out .= '<td style="border:1px solid #e7e7e7; padding:10px; text-align:center">'. $greet->greeting .'</td></tr>';

      $out .= '</table>'; 

        return $out; 


So, if someone types in [db-info] in a post, without any attributes, they aren't getting "My Default" and "1900". If they type in: [db-info title="Hello" year="1973"], it works as expected. What am I doing wrong?



share|improve this question
up vote 3 down vote accepted


 $atts = shortcode_atts( array( 'title' => 'My Default', 'year' => '1900' ), $atts ); 
share|improve this answer
Hi mfields, Thanks so much for the help. That worked great. – Laxmidi Aug 30 '11 at 21:22
No problem :) Glad I could help. – mfields Aug 30 '11 at 21:26

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.