WordPress.org

Ready to get started?Download WordPress

Forums

Squelch Tabs and Accordions Shortcodes
Using [shortcode] inside [accordion] (9 posts)

  1. pauldory
    Member
    Posted 10 months ago #

    I'm curious if anyone knows if this is possible.
    Can you use a shortcode inside the accordion shortcode, like this (see below sitenameshortcode):

    [accordions title="" disabled="false" autoheight="false" collapsible="true"]
      [ accordion title="MyTitleText" [sitenameshortcode] ]
       Some Text
      [/accordion]
    [/accordions]

    http://wordpress.org/plugins/squelch-tabs-and-accordions-shortcodes/

  2. Matt Lowe
    Member
    Plugin Author

    Posted 10 months ago #

    No, the WordPress shortcodes engine is too simplistic for that. While I can see it would be useful if it could do this, the "dumb" way in which it's been built is with an emphasis on speed.

  3. pauldory
    Member
    Posted 10 months ago #

    Matt ... Many places I am using [sitename] as my shortcode ... between the accordion shortcode tags I can use [sitenameshortcode] but within the [accordions] this is a no go ...

    Is it a limitation by WP or the plugin?

    To make it easier for the editors, I have applied the shortcode rule for them, and was hoping there was some solution that would allow that same shortcode to be used within (not between) other shortcodes ...

    In this case, should they ever want to change the name of the site, I figured using shortcode would be perfect .. then I came upon the issue with the accordion plugin ...

    Thanks for your help!

  4. Matt Lowe
    Member
    Plugin Author

    Posted 10 months ago #

    It is a limitation by WP, there is nothing my or any other plugin can do to work around this. The WordPress shortcodes engine is too simplistic to do what you're trying to achieve because it's been built with an emphasis on speed.

    See http://codex.wordpress.org/Shortcode_API#Limitations
    and http://codex.wordpress.org/Shortcode_API#Square_Brackets

    Note that the square brackets rule applies to square brackets ANYWHERE within a shortcode.

  5. pauldory
    Member
    Posted 10 months ago #

    Again, thank you .... and great plugin!

  6. Matt Lowe
    Member
    Plugin Author

    Posted 10 months ago #

    Out of interest what is the output of the [sitename] shortcode?

  7. pauldory
    Member
    Posted 10 months ago #

    It outputs the name of the site, for instance if it were MySiteName, I defined my function to use this as the name wherever the code is used with styling.

    However when used inside the [accordion], it renders blank until it comes to another opening/closing shortcode then continues correctly after that.

    It's purpose is probably obvious ... allowing for the formatting, and naming of the site across all pages and should it ever be changed, it's editted in one place and the update is across the board.

    function post_sitename() {
    	return '<em>MySiteName</em>';
    }
    add_shortcode('sitename', 'post_sitename');
  8. Matt Lowe
    Member
    Plugin Author

    Posted 10 months ago #

    Your original example doesn't quite make sense then:

    [ accordion title="MyTitleText" [sitenameshortcode] ]
       Some Text
      [/accordion]

    If WordPress did allow shortcodes within shortcodes then that would become

    [ accordion title="MyTitleText" <em>MySiteName</em>]
       Some Text
      [/accordion]

    ...which doesn't make any sense.

    This would make more sense:

    [ accordion title="MyTitleText [sitenameshortcode]" ]
       Some Text
      [/accordion]

    But again, sadly this is not currently possible with WordPress. If you really wanted to be able to do something technically equivalent to this then you could write a new shortcode, call it myaccordion for example, which would be used in place of [accordion]. Its only job would be to replace a specific string, %sitename% perhaps with the site name, before passing on the content to the function squelch_taas_accordion_shortcode().

    Then all you've got to do is make sure everyone is using [myaccordion] in place of [accordion] and understands they have to use %sitename% in place of sitenameshortcode. But you're probably going to find you have to do this for every shortcode on your website to make it viable, which would likely get out of hand fast.

  9. pauldory
    Member
    Posted 10 months ago #

    Typo on my part, [sitenameshortcode] and [sitename] are the same ...

Reply

You must log in to post.

About this Plugin

About this Topic