mercredi 10 juillet 2019

Else statement being executed in custom shortcode

I have the following shortcode mapped to display a dropdown field in WPBakery:

array(
    'type' => 'dropdown',
    'heading' => esc_html__( 'Type of container', 'js_composer' ),
    'param_name' => 'container_type',
    'value' => array(
        'Container' => 'container',
        'Container fluid (full width)' => 'container-fluid',
    ),
    'std' => 'container',
    'description' => esc_html__( 'Select whether you want the content to be contained or full width on the screen.', 'js_composer' ),
)

It is being initialised in another file where its attributes and markup is defined:

/**
 * Shortcode attributes
 * @var $container_type
 */

if ($container_type == "container-fluid"){
    echo "container-fluid";
} else {
    echo "container";
}

echo "<p>".$container_type."</p>";

One of my fields is set to 'container-fluid, but anechoof$container_type` is showing "container" (meaning the else statement is being executed. Unsure why?

Aucun commentaire:

Enregistrer un commentaire