How to Set Condition If a Link with an Anchor Exists

I’m trying to set a condition on a navigation link where if the permalink with the anchor does not exist, do not show it.

I set it up as:

{{dc:post:permalink depth=“0”}}#_other_resources is not _____________________________

But it’s still showing up in the navigation even though that anchor does not exist on that page. Any help would be appreciated.

Hi @OctoCog,

Thanks for reaching out.
It is not very clear what exactly you are trying here. Can you please give an example or share any page where you have added such a condition? I would also request you please provide login credentials for your site in a secure note to examine it further, including:

– WordPress Site URL & Login URL
– WordPress Admin username/password
– Specific page and section where this condition is added

To create a secure note, click the key icon underneath any of your posts.

Thanks

Hi @tristup

Thank you for your help. I’ve added a secure note to this post. I’ll give you an example below:

  1. Go to https://bootstrapfostg.wpenginepowered.com
  2. Hover over Curriculum in the main navigation
  3. Hover over the link Physics, you will see a flyout menu that goes to anchor links of the parent navigation page (in this case Physics). The problem is that the link “Other Resources” should not appear because that anchor (#_other_resources) does not exist on the Physics page.

I have created a Component called Curriculum Dropdown Module. There you will see how I set up the flyout menu.

I tried to set up a Condition on the Other Resources button where if the URL {{dc:post:permalink depth=“0”}}#_other_resources is not empty make it visible. But this did not work.

Thank you for the update. Unfortunately, there is no condition to check for URL hash but you can check for URL parameter. Something like this should work:

yes > is > {{ url.param({"key":"other_sources"}) | default('test') }}

The element should display if the “other_sources” parameter is set to “yes”, or if the URL looks something like this**: https://site.com/page/path?other_sources=yes**

Let us know if you need more info.

Best regards,
Themeco

@Ismael Thank you for your help. I just set the condition to what you specified, but all the Other Resources links have now disappeared even though there are some pages that do have the #_other_resources anchor.

You can see this on the staging site I gave you access to.

Hey @OctoCog,

I believe the condition should be {{ url.param({"key":"other_resources"}) | default('test') }} instead of {{ url.param({"key":"other_sources"}) | default('test') }} I checked your setup and I see you’ve other_sources as a key which doesn’t exist in your case.

Let us know how it goes!

@nabeel Thank you for your assistance. I modified the link condition so that it says

yes is {{ url.param({“key”:“other_resources”}) | default(‘test’) }}

All the Other Resources links have dissapeared now even though some of the posts do have the Other Resources anchor (#_other_resources)

An example of this can be seen on the Curriculum > Algebra flyout. The Other Resources link should be visible in the flyout because https://bootstrapfostg.wpenginepowered.com/materials/spring-2025/lessons/algebra-pyret/#_other_resources does exist.

Just so it’s clear the Lessons and Projects link in the flyout is the base link in the example above it is https://bootstrapfostg.wpenginepowered.com/materials/spring-2025/lessons/algebra-pyret. The Other Resources is the same link plus the anchor https://bootstrapfostg.wpenginepowered.com/materials/spring-2025/lessons/algebra-pyret/#_other_resources

Hey @OctoCog,

My colleague @Ismael has mentioned that

You’re URL should be something like

NOT

If that cannot be changed, regretfully, there is no solution for what you need other than custom coding a script which is beyond the scope of our theme support.

We have a service called One support where we can look at creating a custom Javascript to get the hash in the URL.

@christian I understand what you are saying. I’m going to have to see if this is something we can build into the posts to look for. Thank you!

@christian It looks like only a singular material has this issue. I’m going to exclude the Standard Alignments and Other Resources from appearing on this singular material and it should work.

Thank you for your assistance.

Glad to hear that @OctoCog

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.