0

I am developing a plugin and have a shortcode where some info is added. this is called by [info] I would like to be able to add an 'extended' param as a switch so that i can have extended info if i set this [info] would show short info and [info extended] would show extended with something like

   function info($atts){
      extract(shortcode_atts(array(
            'extended' => '',
            ), $atts));
     ob_start();
        echo 'info';
        if (isset($extended)){
            echo 'More info';
            }
      return ob_get_clean();
    }

but can not find how to do this. I only find options where i must add value to the param and check this like [info extended="full"] and then check the value of the param. Anyone got some pointers?

1 Answer 1

0

Yes, you can pass shortcode parameters wihtout values. They just appear on $atts with numeric keys. You can see this when you do var_dump($atts). One option to check their existance is then to use in_array().

function info( $atts ) {
    // check if extended is passed in $atts with or without value
    $extended = isset( $atts['extended'] ) ? $atts['extended'] : in_array( 'extended', $atts );

    if ( $extended ) {
        // do something
    }

    // more code
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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