• Resolved davidjazz

    (@davidjazz)


    Simple code to pass attributes from shortcode to snippets fails, nothing is sent to the $atts parameter. Shortcode is [fj_testfish count=”home” fred=”fish”]
    Code is
    function fj_shortparam($attr){
    $args = shortcode_atts( array(
    ‘count’ => ‘not found’
    ), $attr );

    $output = count($attr) . ‘ ‘ . $args[‘count’];
    return $output;
    }

    function fj_test($atts=[]) {
    return ‘ param ‘ . fj_shortparam($atts) . ‘ ‘ . ‘no content’. ‘<br/>’;
    }

    add_shortcode(‘fj_testfish’, function() {
    return fj_test();
    } );`

    I am using Flywheel Local. All I want to do is pass a simple parameter to the snippet. I am probably doing something stupid, and I can’t see it.

    Help, please lyond@essex.ac.uk

    Dave
    `

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

    (@bungeshea)

    Hi Dave,

    I’m not really sure what exactly you are trying to do here, but you need to be accepting attributes within the shortcode function the very least:

    add_shortcode( 'fj_testfish', function ( $atts ) {
    	return fj_test( $atts );
    } );

    In fact, you could combine all of your code into a single function like so:

    add_shortcode( 'fj_testfish', function ( $atts ) {
    
    	$atts = shortcode_atts( array(
    		'count' => 'not found',
    	), $atts );
    
    	$output = count( $atts ) . ' ' . $atts['count'];
    
    	return ' param ' . $output . ' ' . 'no content' . '<br/>';
    } );

    Hope this helps!

Viewing 1 replies (of 1 total)

The topic ‘code snippets attributes fail’ is closed to new replies.