errors - Shortcode Attribute not defined

I have a shortcode [gf_popup pause="1000"location="bottom"] and the location attribute keeps comin

I have a shortcode [gf_popup pause="1000" location="bottom"] and the location attribute keeps coming back as Uncaught ReferenceError: bottom is not defined. Any thoughts on why? Here is the main part of the code:

function gfpu_shortcode($atts = [], $content = null, $tags = '')
{

    // normalize attribute keys, lowercase
$atts = array_change_key_case((array)$atts, CASE_LOWER);

// override default attributes with user attributes
$gfpu_atts = shortcode_atts([
                                 'pause'    => 5000,
                                 'location' => 'false',
                                 'popTrigger'   => 'false',
                             ], $atts, $tag);

    $timer = esc_html__($gfpu_atts['pause'], 'gf_popup');
    $location = esc_html__($gfpu_atts['location'], 'gf_popup');
    $popTrigger = esc_html__($gfpu_atts['popTrigger'], 'gf_popup'); 

}
add_shortcode('gf_popup', 'gfpu_shortcode');

Any thoughts?

I have a shortcode [gf_popup pause="1000" location="bottom"] and the location attribute keeps coming back as Uncaught ReferenceError: bottom is not defined. Any thoughts on why? Here is the main part of the code:

function gfpu_shortcode($atts = [], $content = null, $tags = '')
{

    // normalize attribute keys, lowercase
$atts = array_change_key_case((array)$atts, CASE_LOWER);

// override default attributes with user attributes
$gfpu_atts = shortcode_atts([
                                 'pause'    => 5000,
                                 'location' => 'false',
                                 'popTrigger'   => 'false',
                             ], $atts, $tag);

    $timer = esc_html__($gfpu_atts['pause'], 'gf_popup');
    $location = esc_html__($gfpu_atts['location'], 'gf_popup');
    $popTrigger = esc_html__($gfpu_atts['popTrigger'], 'gf_popup'); 

}
add_shortcode('gf_popup', 'gfpu_shortcode');

Any thoughts?

Share Improve this question asked Jun 23, 2019 at 19:18 ParkbumParkbum 231 silver badge3 bronze badges 2
  • Is your default 'false' actually being parsed as false? If that's the case and its registering the default as a boolean could be expecting a string but getting a boolean? Long shot, as I think variables hold both interchangeably. – Dan Sutherland Commented Jun 23, 2019 at 22:17
  • 2 Uncaught ReferenceError is a JavaScript error. Is there any JavaScript associated with this shortcode? – Jacob Peattie Commented Jun 24, 2019 at 0:59
Add a comment  | 

1 Answer 1

Reset to default 0

If you look at the defaults for location and popTrigger they have single quotes around them...

Assuming this is correct you need to add these around the new location value, so it does not think bottom is an (undefined) javascript variable, but rather a string value, via providing 'bottom'...

Or if you don't want to modify code to add the single quotes, you could also just do: [gf_popup pause="1000" location="'bottom'"] to pass the single quotes in via the shortcode attribute.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745375541a4624982.html

相关推荐

  • errors - Shortcode Attribute not defined

    I have a shortcode [gf_popup pause="1000"location="bottom"] and the location attribute keeps comin

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信