• Hi there,

    I’m having trouble using CCS shortcodes inside of any kind of HTML tag. The shortcodes work as expected outside of the tag, and then as soon as I wrap them in a tag (href, style, etc.), they stop working.

    Here’s the full code of what I’m trying to do –

    [for each=category parents=true exclude=uncategorized count=5]
      <div class="category-box">
        <div class="category-image">
            <a href='[each url]'>
            [each field image=thumbnail_image]
            </a>
            </div>
        <div class="category-name">[each link]</div>
      </div>
    [/for]

    [each url] works great outside the href tag, but once inside, it stops rendering. Any ideas? Thanks!!

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Hi, sorry for the late reply..

    I’ve seen this issue before, with shortcodes inside HTML attributes such as “href”. Typically it’s caused by code (HTML+shortcodes) that’s outside of normal post content, for example, in a visual builder of some kind. If that’s the case, it may be possible to work around it by keeping the code in its own post, and pulling that content into the place where you need it.

    For example, if you put the above code block in a custom post type called template with the name category-list, you can display it like [content type=template name=category-list].

    The plugin uses the the_content filter to handle nested shortcodes and shortcodes in HTML attributes in the correct order, but when other plugins or the theme uses do_shortcode directly, they’re not handled properly – usually by running the shortcodes in HTML attributes first (outside of the loop).

    I hope that helps!

    Hello,

    I have the same issue, try to render an ACF image field (named logo) of a custom taxonomy (named brands) in a Beaver Builder HTML module outside of the CPT:

    [for each=brands]
        [each logo]
        <img src="[each logo]">
    [/for]

    [each logo] renders the images URL ok
    <img src="[each logo]"> renders <img src(unknown)>

    I wonder if there’s a way to catch and pass the [each logo] output to another shortcode?

    • This reply was modified 6 years, 8 months ago by studioavanti.

    Hi,

    I found a solution on ACF side: just change the image value type returned from URL to Object (array).
    Simple as that, and it works, images show up embedded in <a> tags, yesss!

    • This reply was modified 6 years, 7 months ago by studioavanti.

    Ah, too bad, my CCS image rendering in a link issue is solved and now i have the same issue as @irenehardy: unable to render an ACF URL field in HTML using CCS…

    [for each=brands]
        [each website_url]
        <a href="[each website_url]">[each website_url]</a>
    [/for]

    The first and third [each website_url] render the URL.
    The second doesn’t.
    I guess because it’s inside the <a> tag, maybe because of the quotes…
    Any idea please?

    I solved a similar problem with html tags inside Contact Form 7. Instead of putting the code into a custom post type as a template as Eliot suggested (which is a great idea for solving lots of WordPress problems!), I put the html into a my own shortcode, and inserted the other shortcode data into it. In my case I was creating <option> tags for a select box:

    function option_shotcode($atts, $content=null) {
    return ‘<option value=”‘.$content.'”>’.$content.'</option>’;
    }
    add_shortcode(“option_shortcode”, “option_shortcode”);

    Then I used it like this:

    [loop type=post]
    [option_shortcode][field author][/option_shortcode]
    [/loop]

    I had the same problem with URL’s I needed to capture a link for an external affiliate site with ACF but I just could not get it to work on the front end when wrapped in <a href> so I modified @taylorswendsen suggestion above. I created a [acf_link] shortcode like this:

    add_shortcode("acf_link", "link_shortcode");
    function link_shortcode($atts, $content=null) {
    return '<a href="'.$content.'" class="button">Shop Now</a>';
    }
    

    then used it like this:

    [acf_link][field product1_link][/acf_link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Shortcodes not working inside’ is closed to new replies.