• This issue involves a few very simple shortcodes used within an anchor (link) tag’s attribute values. Each shortcode, when used individually, renders as it should, however once a third shortcode is used, even if it’s the same shortcode as one previously used, each of the shortcodes render as the shortcode code.

    My goal is to make shortcodes that will add settings (theme mods set up in Customizer) to a link.

    Here is the code used in the page editor:
    <a href="[ticketurl]" target="[tickettarget]" data-target2="[tickettarget]">Purchase Tickets</a>

    Note that each one of these shortcodes used individually render just fine. The use of two of the shortcodes also renders fine for each. It’s when I add a third shortcode that each of the shortcodes renders as the shortcode itself.

    The simple shortcode functions are written as follows:

    function cpac_ticketurl_shortcode() {
    	$output = esc_url(get_theme_mod('cpac_ticketingurl'));
    	return $output;
    }
    add_shortcode('ticketurl','cpac_ticketurl_shortcode');

    and

    function cpac_tickettarget_shortcode() {
    	$output = esc_attr(get_theme_mod('cpac_ticketingtarget'));
    	return $output;
    }
    add_shortcode('tickettarget','cpac_tickettarget_shortcode');

    Using these shortcodes:

    <a href="[ticketurl]" target="[tickettarget]">Purchase Tickets</a>
    renders as:
    <a href="http://www.buytickets.com/" target="_blank">Purchase Tickets</a>
    while
    <a href="[ticketurl]" target="[tickettarget]" data-target2="[tickettarget]">Purchase Tickets</a>
    renders as:
    <a href="[ticketurl]" target="[tickettarget]" data-target2="[tickettarget]">Purchase Tickets</a>

    I should also note – even when the data-target2 value is set to a different shortcode that was not previously used, it still breaks all shortcodes within the anchor (link) tag.

    I have not seen any limitations on multiple shortcode use within a single HTML tag, so I’m wondering what I might be doing wrong. I’m still a bit of a noob at this WordPress coding.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    inside your shortcode, you need to expand shortcodes, so something like

    return do_shortcode($output);

    assuming there’s a shortcode inside of $output

    Thread Starter midimatt

    (@midimatt)

    There’s not a shortcode inside of $output. $output is just a string. That string is either a URL or a target, such as “_blank”. They’re being obtained from the get_theme_mod function.

    • This reply was modified 9 years, 7 months ago by midimatt.
    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    1. are these shortcodes you wrote or do they come from the theme or a plugin?

    2. There’s probably a sanitize function hooked into the_content that is “cleaning up” those links and removing the sortcodes.

    Thread Starter midimatt

    (@midimatt)

    I wrote the shortcodes. They’re pretty straightforward. Each returns a simple string.

    If there is a sanitize function that’s “cleaning” up the link, it’s not doing a very good job… There’s no invalid data (characters or otherwise) within the returned data. Nothing a link attribute can’t handle. One value is escaped as a URL, and the other as an attribute – so there shouldn’t be any unacceptable characters.

    I should also mention – The site isn’t public – I have it running locally using XAMPP. I doubt that makes a difference, but in case it does I’ll mention it.

    • This reply was modified 9 years, 7 months ago by midimatt. Reason: additional info
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Using multiple shortcodes in single HTML tag breaks shortcode rendering’ is closed to new replies.