1

Hi I am developing a custom post type plugins. Which has shortcode support. Already i have created a shortcode which is going to use for default layout design. Again i have to create a onemore shortcode for another layout design.

My current shortcode [testimonial]

i want the shortcode something like this [testimonial style="fancy"]. How can i do it.can any one suggest me .

Thanks

2
  • CPT with shortcode doesn't really match. What exactly are you trying to do? What does testimonial shortcode do? Please explain more.
    – sakibmoon
    Commented Aug 16, 2014 at 6:01
  • created a CPT testimonial plugin . when i use [testimonial] shortcode it displays default layout design option . i have couple of designs so when i use [testimonial style="fancy"] it need to display another layout design.
    – Jagankumar
    Commented Aug 16, 2014 at 6:04

1 Answer 1

0

You need to capture the attributes that passed to a shortcode. You can do that like this

add_shortcode('testimonial', 'testimonial_shortcode_func');
function testimonial_shortcode_func( $atts ) {
    $atts = shortcode_atts( array(
      'style' => 'default_value_if_no_value_is_provided',
    ), $atts );

    if( $atts['style'] == 'fancy' ) {
        //do something
    } else if ( $atts['style'] == 'something_else' ) {
        //do something
    }
    //And so on
    //finally return content, don't echo just return
}

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.