Created
November 14, 2025 09:45
-
-
Save annuman97/b8e9841f7d33637269093412c50e2131 to your computer and use it in GitHub Desktop.
Enrolled course tab in Commumity Navbar.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Put this in: theme's functions.php OR a small custom plugin OR Code Snippets. | |
| add_action('fluent_community/after_header_menu', function ($context) { | |
| ?> | |
| <script> | |
| (function () { | |
| // Change this selector if your menu item key is different | |
| const MENU_ITEM_SELECTOR = '.fcom_menu_item_fcom_custom_teset a'; | |
| document.addEventListener('click', function (e) { | |
| const link = e.target.closest(MENU_ITEM_SELECTOR); | |
| if (!link) { | |
| return; | |
| } | |
| // We are hijacking only this menu item | |
| e.preventDefault(); | |
| // Helper: after courses page is visible, click the "My Courses" tab | |
| function activateMyCoursesTab() { | |
| // Adjust the label if you translated it (e.g. "আমার কোর্স") | |
| const TARGET_LABELS = ['My Courses', 'Enrolled']; | |
| const buttons = document.querySelectorAll('button, a, [role="tab"]'); | |
| for (const el of buttons) { | |
| const text = (el.innerText || el.textContent || '').trim(); | |
| if (TARGET_LABELS.includes(text)) { | |
| el.click(); | |
| break; | |
| } | |
| } | |
| } | |
| // If Vue app is available, use router | |
| if (window.fcomLayoutRef && window.fcomLayoutRef.$router) { | |
| // Go to /courses route first | |
| window.fcomLayoutRef.$router.push({ name: 'courses' }).then(function () { | |
| // Give Vue some time to render the courses view | |
| setTimeout(activateMyCoursesTab, 400); | |
| }).catch(function () { | |
| // Fallback: full page load if router push fails | |
| window.location.href = link.href; | |
| }); | |
| } else { | |
| // Absolute fallback: normal navigation | |
| window.location.href = link.href; | |
| } | |
| }, true); // capture = true, to run before other handlers | |
| })(); | |
| </script> | |
| <?php | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment