Hello – following back up here as it’s been almost 2 weeks.
Can anyone point me in the right direction here? Here is an example of the static export page with the issue: https://ericelliot.com/dev/sra/collaboration/start/index.html
As you scroll the page, you’ll see there is a sub nav with several nav items (Overview, Process, Apply, FAQ, Recipients). These links have an “active” class applied to them for whichever is the current page on the WordPress site. However as you can see in static export, those classes are not applied to the current menu option. Any insight would be appreciated, as this is a pretty basic / standard feature of WordPress navigation menus. Thanks!
Hey @ees2025,
thanks for the follow-up!
If I had to make a wild guess, given that I can only see the static site, I would say it’s because of the URL structure configured in Simply Static.
Try re-running the export, but choose “Absolute URLs” instead of the relative path this time.
Often, the JS used to do these things is using URL parsing, and the relative path might cause the issue here, as the host is missing from the current URL.
Hey @patrickposner – thanks for the reply. Unfortunately I can’t share the live WordPress site URL or credentials to it. I just tried generating a static version using absolute URLs, but issue of the missing active class persists.
I can tell you that the active class is applied by first matching the current page URL against the URL of each of those sub nav items. This is done in the PHP template for those pages with some simple variables as follows:
$current_url = trailingslashit(home_url(add_query_arg([], $_SERVER['REQUEST_URI'])));
// Loop through the rows of data
while (have_rows('collab_subnav')) : the_row();
$subnav_link = get_sub_field('nav_link');
if ($subnav_link):
$subnav_url = trailingslashit($subnav_link['url']);
$is_active = ($subnav_url === $current_url);
These classes were correctly applied back when we were using WP2Static, so I’m trying to figure out how to make it work properly with Simply Static. Any other thoughts on what else we could try?
Hey @ees2025,
thanks for the follow-up!
That’s a bit out of scope regarding our free support (we avoid doing any code-related stuff here).
However, I would probably handle it via JavaScript instead of PHP.
I’m sure there was a valid reason for that back in the day, but you probably get to your desired result quicker by parsing the URL via JS and having the $subnav_url as part of the DOM (as a meta tag, for example) to compare based on the DOM elements.