Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #257814
    Paul
    Participant

    Hi,
    I’m using the Code Snipetts plugin – https://wordpress.org/plugins/code-snippets/ – and followed the instructions in the support forum – https://wordpress.org/support/topic/passing-a-function-argument-through-the-shortcode/ – 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

    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

    The error report mentions teh Kathmandu theme, is there a conflict?

    Thanks

    Paul

    #257868
    Skandha
    Keymaster

    @paul-mac: Hello Paul,
    Can you please post in your site URL so that I can look into the issue?

    Kind Regards,
    Skandha

    #257887
    Paul
    Participant

    The page is not live, it is still being developed on my local machine. But never mind I’ve been in contact with the plugin developer and he pointed me in the right directions.

    I needed to add the following bit of code to the snipett:

    add_shortcode( ‘introduction’, function ( $atts ) {
    $atts = shortcode_atts( array(
    ‘locn’ => ”,
    ), $atts );

    Thanks for getting back to me though.

    Paul

    #257893
    Skandha
    Keymaster

    @paul-mac: Glad you were able to figure it out. Have a good day! 🙂

    Kind Regards,
    Skandha

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.