Title: code snippets attributes fail
Last modified: January 8, 2022

---

# code snippets attributes fail

 *  Resolved [davidjazz](https://wordpress.org/support/users/davidjazz/)
 * (@davidjazz)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/code-snippets-attributes-fail/)
 * 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](https://wordpress.org/support/topic/code-snippets-attributes-fail/lyond@essex.ac.uk?output_format=md)
 * Dave
    `

Viewing 1 replies (of 1 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/code-snippets-attributes-fail/#post-15362513)
 * 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.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [4 years, 2 months ago](https://wordpress.org/support/topic/code-snippets-attributes-fail/#post-15362513)
 * Status: resolved