• Resolved dvansoye

    (@dvansoye)


    I am using Multisite and having snippets at the network level (for all sites) is a game changer for us. The only thing that is missing is the ability to pass parameters.

    Basically, I want to add the shortcode and pass parameters that then can be used within the snippet shortcode. I looked through the documentation but didn’t see it. Did I just miss it?

    Here’s an example:

    [snippet var1=”foo” var2=”bar”]

    Then, inside the snippet, I would be able to reference these variables.

    This is similar to the way that Reusable Text Blocks By Hal Gatewood works. I like Snippets better. Much more powerful and covers so many use cases.

Viewing 1 replies (of 1 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hello,

    You can certainly do this. You just need to add $atts as the first parameter to the shortcode function, like this:

    add_shortcode( 'shortcode_name', function ( $atts ) {
    	// shortcode content goes here
    	return 'my favourite color is ' . esc_html( $atts['color'] );
    } );

    Then, you can pass attributes to the shortcode like this:

    [shortcode_name color="blue"]

    And access those attributes in the function like $atts['color'].

Viewing 1 replies (of 1 total)
  • The topic ‘Feature Request – Pass Parameters’ is closed to new replies.