Skip Navigation

[Resolved] Using ShortCodes in a HREF link

This thread is resolved. Here is a description of the problem and solution.

Problem:
Can we use ShortCodes within HTML "href" links?

Solution:
Yes.
This is the syntax:

<a href="[shortcode you use for the URL]" class="any-class">[shortcode you use for the title]</a>

Note:
- Nested apostrophes must be either single or double, never mixed.
"''" or '""'
- usually, you want a "raw" value in the href part, hence tell the ShortCode to return raw values with the provided attribute it has

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 2 voices.

Last updated by Charles 6 years, 9 months ago.

Assisted by: Beda.

Author
Posts
#619194

Hi,

I am trying to execute a 3rd party shortcode from View which will popup an appointment booking form with calendar when a button is clicked. Here's my html code under Loop item in View:

[wpml-string context="wpv-views"]Book a tour[/wpml-string]

The shortcode "sg_popup" works in a post/page but doesn't work this way. How can I make it work? Your help is most appreciated..

What is the link to your site?
hidden link

#619330

I honestly don't know.

The first test I suggest is this:

1. Insert this code into a simple Post Body, in text mode:

<a href="[sg_popup id=1]" class="btn btn-tour">[wpml-string context="wpv-views"]Book a tour[/wpml-string]</a>

Does it "work"?
If no, then this issue has to be directed to the creator of that ShortCode, which is not Toolset.

2. If it works, please let me know the exact output of the ShortCode (inclusive eventual HTML)

I assume it produces a bit more than a URL and breaks the HTML Link.

I don't think this is a Toolset issue.
What I can think of is that your ShortCode's ID attribute expects something like a Post ID, hence passing "1" is wrong, in a Post View Loop.
[wpv-post-id] would be better in this case (given the 3rd party ShortCode accepts nested ShortCodes, which is not granted).

Please let me know the results.

#619578
Screen Shot 2018-02-26 at 11.37.21 AM.png

The <a> itself doesn't work. It gives the message: "Sorry, but the page you were trying to view does not exist." But if using the shortcode: "[sg_popup id=1]" alone in the post body, it works as attached. How can I get this to pop in View?

#620011

Well, it seems this ShortCode produces a whole lot more than a simple URL?

In that case, you can logically not use it as an "a href=" parameter.

This is the HTML that has to be created by a "a href":

<a href="www.url.com" class="any-class">Any Text</a>

If your shortcode "[sg_popup id=1]" produces what I see in the ScreenShot, then this is much more than a URL.
It's a whole calendar and a Form.

This can not be used as a URL href, as that needs to be an URL.

Since you use this ShortCode as a standalone in the Single Posts, it also needs to be used as a StandAlone in the Views loop.
Since it seems to accept an ID, you can try to pass the dynamic ID [wpv-post-id] which will make sure to give the right ID to the ShortCode.

#620072

Thanks Beda. That will definitely work if I link to a post where the shortcode is called.