Title: Parameter passing
Last modified: September 1, 2020

---

# Parameter passing

 *  Resolved [pauldotmac](https://wordpress.org/support/users/pauldotmac/)
 * (@pauldotmac)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/parameter-passing/)
 * Hi,
    I followed the other posting instructions re parameter passing with the 
   following code snipett
 * add_shortcode( ‘introduction’, function($atts){
 *  $locn = $atts[“locn”];
    $output = “”; $output .= ‘<h1>Assessment Planner – ‘.
   $locn.'</h1>’; $output .= ‘<table id=”chance”><tr><td style=”width: 12%”>% Chance:
   </td><td><span id=”legendContainer” class=”legend” style=”border-style: solid;
   border-color: threedface; width: 100%”> </span></td></tr></table>’;
 *  return $output;
    });[http://localhost/risk/wp-admin/edit.php?post_type=page](http://localhost/risk/wp-admin/edit.php?post_type=page)
 * and get the following error report
 * Warning: Illegal string offset ‘locn’ in H:\sites.web\risk\wp-content\plugins\
   code-snippets\php\snippet-ops.php(446) : eval()’d code on line 3
    Call Stack #
   Time Memory Function Location 1 0.0002 410016 {main}( ) …\index.php:0 2 0.0005
   410288 require( ‘H:\sites.web\risk\wp-blog-header.php’ ) …\index.php:17 3 0.1488
   5806184 require_once( ‘H:\sites.web\risk\wp-includes\template-loader.php’ ) …\
   wp-blog-header.php:19 4 0.1573 5894984 include( ‘H:\sites.web\risk\wp-content\
   themes\catch-kathmandu-pro\page.php’ ) …\template-loader.php:106 5 0.2095 6080256
   get_template_part( ) …\page.php:22 6 0.2096 6086408 locate_template( ) …\general-
   template.php:204 7 0.2576 6086520 load_template( ) …\template.php:676 8 0.2577
   6086856 require( ‘H:\sites.web\risk\wp-content\themes\catch-kathmandu-pro\content-
   page.php’ ) …\template.php:732 9 0.2599 6153896 the_content( ) …\content-page.
   php:25 10 0.2601 6153920 apply_filters( ) …\post-template.php:253 11 0.2601 6154320
   WP_Hook->apply_filters( ) …\plugin.php:206 12 0.2609 6157080 do_shortcode( ) …\
   class-wp-hook.php:287 13 0.2609 6159408 preg_replace_callback ( ) …\shortcodes.
   php:218 14 0.2609 6160024 do_shortcode_tag( ) …\shortcodes.php:218 15 0.2610 
   6160024 {closure:H:\sites.web\risk\wp-content\plugins\code-snippets\php\snippet-
   ops.php(446) : eval()’d code:1-9}( ) …\shortcodes.php:343
 * The shortccode on the page is
 * [introduction locn=”UNITED KINGDOM”]
 * It works fine without reference to $atts[“locn”] in line 3 and $locn in line 
   5
 * Any suggestions?
 * Thanks
 * Paul

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/parameter-passing/#post-13346556)
 * You should be using the `shortcode_atts` function to ensure that all attributes
   are present before attempting to access them. Change the first line of the snippet
   to this:
 *     ```
       add_shortcode( 'introduction', function ( $atts ) {
           $atts = shortcode_atts( array(
               'locn' => '',
           ), $atts );
       ```
   
 *  Thread Starter [pauldotmac](https://wordpress.org/support/users/pauldotmac/)
 * (@pauldotmac)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/parameter-passing/#post-13346989)
 * Hi,
 * Thanks for the quick response. I’ve made the change and I no longer get the error
   message but the passed parameter is not being picked up.
 * The line $output .= ‘<h1>Assessment Planner – ‘.$locn.'</h1>’; just produces “
   Assessment Planner – ” without UNITED KINGDOM.
 * Thanks
 * Paul
    -  This reply was modified 5 years, 8 months ago by [pauldotmac](https://wordpress.org/support/users/pauldotmac/).
 *  Thread Starter [pauldotmac](https://wordpress.org/support/users/pauldotmac/)
 * (@pauldotmac)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/parameter-passing/#post-13348524)
 * Don’t what happened but it now working. Thanks.
 * Paul
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/parameter-passing/#post-13349579)
 * Glad to hear, Paul – might have been a caching issue.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Parameter passing’ 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/)

 * 4 replies
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [5 years, 8 months ago](https://wordpress.org/support/topic/parameter-passing/#post-13349579)
 * Status: resolved