WordPress.org

Ready to get started?Download WordPress

Forums

Third parameter to shortcode callback is never populated (5 posts)

  1. jarrowwx
    Member
    Posted 2 years ago #

    I'm trying to do something really fun, really clever, and if I get it to work, it will totally kick some serious butt...

    But it all hinges on my shortcode function being able to get the name of the shortcode tag that was matched. I've looked at the documentation. It says the third parameter is the tag name. I've looked at the code. It really LOOKS like it should be passing back the shortcode as the third parameter.

    But no matter how hard I try, I can not get the matched shortcode name. It's not in $attr[0]. It's not in $content. It's not in the third parameter.

    Can anyone actually get the shortcode name in the third parameter in 3.2.1?

  2. jarrowwx
    Member
    Posted 2 years ago #

    Nevermind, it is in $attr[0] - here's where I went wrong:

    function shortcode_template( $attr = null, $content = null, $shortcode = null ) {
    ...
      if ( ! isset( $shortcode ) ) {

    It should have been

    if ( empty( $shortcode ) ) {

    Silly me. Why did I think isset() would return false?

  3. Perphide
    Member
    Posted 2 years ago #

    I also can't get $attr[0] to echo... how did you solve this?
    I just want the name of the used shortcode in a variable, that's all.

  4. jarrowwx
    Member
    Posted 2 years ago #

    Post your code that you are using. Then also, post the way you are using the shortcode. That is, are you using it with content, or not, with attributes, or not, and is the shortcode name the same as your function name, or not. Lay it all out so we can look at what you did.

  5. Perphide
    Member
    Posted 2 years ago #

    I fixed this issue last night, but I am not sure if it is the correct way, see this topic: here

    The reason is: I am checking if $content is null, and then I use $shortcode... seems stupid, but it is the only way that I got it working...

Topic Closed

This topic has been closed to new replies.

About this Topic