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?





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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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