Skip Navigation

[Resolved] Using wpv-conditional with anchor tag from URL

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

Problem:
Can we somehow listen or display an anchor tag (hash) from an URL with Toolset?
As example if the URL says mysite.com/#anchortag, can we display /#anchortag in the Content using Toolset?

Solution:
No.
The Anchor Hash is not sent to the Server, so a PHP method here will not work.

There is a StackOverflow post on exactly that topic:
http://stackoverflow.com/questions/2317508/get-fragment-value-after-hash-from-a-url-in-php/

It would require a Custom JS Solution.

This support ticket is created 7 years, 6 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Tristian 7 years, 6 months ago.

Assisted by: Beda.

Author
Posts
#446905

I am trying to:

Add CSS (class="active") to the post in the loop that matches the anchor tag (#v1234) in my URL

I visited this URL:

URL = hidden link

I expected to see:

How do I use [wpv-conditional] to display class="active" if the current URL contains #v[wpv-post-id]

Instead, I got:

I have searched the forums and tried various shortcodes. I can get a URL parameter but not an anchor tag from the current URL.

#447123

Toolset does not provide methods to get the Anchor Tag.

What you can do is, get the Site URL, the Post Slug, or a URL Query Argument, but that will look for a "=" in the URL as well.

The Anchor Hash is not sent to the Server, so a PHP method here will not work.

There is a StackOverflow post on exactly that topic:
http://stackoverflow.com/questions/2317508/get-fragment-value-after-hash-from-a-url-in-php/

This is custom Code that I can not assist, it will require Custom JS Code to listen to that fragment.
And JS can not be used in an HTML Editor of Content Templates or Views in an HTML Conditional.

It is not suggested to do it, but you can use <script> tags in there.
But that will break your Conditional.

So even with Custom Code, I do not see an easy approach to solve this.

#447140

Ok, thanks. I thought it would be a bit easier than that. I'll look for another solution...

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.