Jump to content

Recommended Posts

Hi there,

I'm new to WHMCS and would like to get some guidelines how to setup a hook or any straight-forward direction how to edit the label of my "Knowledgebase" primary and secondary navigations into FAQs? (instead of Knowledgebase).

I would also like to add a new external link for the same navs as above which I will label as my official "Knowledgebase".

Modifications should result into:

1. WHMCS Knowledgebase edited label into FAQs
2. Added new Knowledgebase external link

Thank you for the further help.

Share this post


Link to post
Share on other sites
14 hours ago, Mauwiks said:

I'm new to WHMCS and would like to get some guidelines how to setup a hook or any straight-forward direction how to edit the label of my "Knowledgebase" primary and secondary navigations into FAQs? (instead of Knowledgebase).

there are two ways - either use a hook, or if you only want to change the label of a default navbar/sidebar, you can use a Language Override... though you'd have to add an override for each language that you want to change the label for.

so if wanting to use an override..

$_LANG['knowledgebasetitle'] = "Brian's FAQs";

hwiFAax.png

WrH5Ctn.png

15 hours ago, Mauwiks said:

I would also like to add a new external link for the same navs as above which I will label as my official "Knowledgebase".

you need to decide where that link is going to be (navbar and/or sidebar), and whether the user needs to be logged in or not to see the new link - the answers to those questions will determine the required code.

the Navbar Cheatsheet documentation may be of help to you, but there are plenty of similar working navbar examples posted in the forums... if you can't figure it out, then you ask for specific help.

as an example, if you wanted to change the links on the existing knowledgebase navbar./sidebar links, then you could use the hook posted in the thread below...

 

 

Share this post


Link to post
Share on other sites

 

1 hour ago, brian! said:

there are two ways - either use a hook, or if you only want to change the label of a default navbar/sidebar, you can use a Language Override... though you'd have to add an override for each language that you want to change the label for.

so if wanting to use an override..


$_LANG['knowledgebasetitle'] = "Brian's FAQs";
2

Thank you very much for your response. Much appreciated.

I would prefer what is easier and cannot be overridden by an upgrade.

1 hour ago, brian! said:

you need to decide where that link is going to be (navbar and/or sidebar), and whether the user needs to be logged in or not to see the new link - the answers to those questions will determine the required code.

Both Navbar and sidebar, and I want everyone can have access to it whether they are logged in or not.

Please let me know if you could give me some coded sample

Share this post


Link to post
Share on other sites
21 hours ago, Mauwiks said:

I would prefer what is easier and cannot be overridden by an upgrade. 

neither using language overrides or hooks should get overwritten during an upgrade.

21 hours ago, Mauwiks said:

Both Navbar and sidebar, and I want everyone can have access to it whether they are logged in or not. 

Please let me know if you could give me some coded sample

the following hook should work...

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
	if (!is_null($primaryNavbar->getChild('Knowledgebase'))) {
		$primaryNavbar->getChild('Knowledgebase')->setLabel('FAQs');
		$primaryNavbar->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('http://www.google.com')->setOrder(30);
	}

	if (!is_null($primaryNavbar->getChild('Support'))) {
		$primaryNavbar->getChild('Support')->getChild('Knowledgebase')->setLabel('FAQs');
		$primaryNavbar->getChild('Support')->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('http://www.google.com')->setOrder(30);
	}
});

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
	if (!is_null($secondarySidebar->getChild('Support'))) {
		$secondarySidebar->getChild('Support')->getChild('Knowledgebase')->setLabel('FAQs');
		$secondarySidebar->getChild('Support')->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('http://www.google.com')->setOrder(30)->setIcon('far fa-books');
	}
});

so screenshots below show what the navbar should look like for non-logged in users, logged in clients and the sidebar...

Co2GCBm.png

kJCeXQf.pngTcdwBky.png

  • Like 1

Share this post


Link to post
Share on other sites

You're a lifesaver! Thank you very much for this useful information and the time... If you will ever need my help further, please contact me at <removed>

Share this post


Link to post
Share on other sites

I will try it now but I need to finish my issues with updating the software... Thank you once again!

Share this post


Link to post
Share on other sites

I uploaded a .php file into /includes/hooks on my whmcs document root but it doesn't work.

Is there something I've missed?

Share this post


Link to post
Share on other sites

Everything worked well but I decided to do the language overrides (changed the Knowledgebase text to FAQs) and then add a new menu using hooks function but my site returns an error after that:

I followed this https://docs.whmcs.com/Client_Area_Navigation_Menus_Cheatsheet#Adding_a_Menu_Item

and then changed from your code to this:

----------

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
	if (!is_null($primaryNavbar->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))
->setURI('https://kindtechgroup.net/support')
->setOrder(30);
	}

	if (!is_null($primaryNavbar->getChild('Support'))) {
		$primaryNavbar->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))
->setURI('https://kindtechgroup.net/support')->setOrder(30);
		
		}
});

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar) 
{ if (!is_null($secondarySidebar->getChild('Support'))) { $secondarySidebar->getChild('Support')->addChild('kb2')
->setLabel(Lang::trans('knowledgebasetitle'))->setURI('https://kindtechgroup.net/support')
->setOrder(30)->setIcon('far fa-books'); } });

 

I know something's wrong with my code. Please enlighten me

 

 

 

Share this post


Link to post
Share on other sites
12 hours ago, Mauwiks said:

I know something's wrong with my code. Please enlighten me

this should work..

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) {
	
	$client = Menu::context("client");
	if (!$client) {
		$primaryNavbar->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('https://kindtechgroup.net/support')->setOrder(30);
	}

	if (!is_null($primaryNavbar->getChild('Support'))) {
		$primaryNavbar->getChild('Support')->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('https://kindtechgroup.net/support')->setOrder(30);		
	}
});

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar) {
	if (!is_null($secondarySidebar->getChild('Support'))) {
		$secondarySidebar->getChild('Support')->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('https://kindtechgroup.net/support')->setOrder(30)->setIcon('far fa-books');
	}
});

i'm assuming that you want non logged-in users see it on the navbar and logged-in clients to see it within the support dropdown on the navbar - if so the above should do it... if you want everyone to see the KB link in the same place on the navbar,whether logged in or not,

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) {
	
	$primaryNavbar->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('https://kindtechgroup.net/support')->setOrder(30);

});

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar) {
	if (!is_null($secondarySidebar->getChild('Support'))) {
		$secondarySidebar->getChild('Support')->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('https://kindtechgroup.net/support')->setOrder(30)->setIcon('far fa-books');
	}
});
  • Like 1

Share this post


Link to post
Share on other sites

I restored my installation because of the error.

And I decided to keep the "knowledgebase" term instead and just add a new Menu as follows:

PrimaryNavMenu and SecondaryNavMenu for (logged in users or not):

1. Add new "Support" Menu with an external link to https://kindtechgroup.net/support

2. Under the Support SubMenu, add a new Menu with the same link labeled as Support Center

3. Add "Support Center" under the Support (SideBar Header) but change the label of the (SideBar Header) to "Support Panel"

If this is too much, can you give me a hint for #1 instead? Thanks further. I've searched for a while but it doesn't fit my needs

Share this post


Link to post
Share on other sites

Actually, instead of "Support Panel", I think it's better to rename it with "Resources" and as well as the "Support" (Parent Menu) in the client area when users are logged in

Share this post


Link to post
Share on other sites

1. is basically going to be...

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
	if (is_null($primaryNavbar->getChild('Support Center'))) {
		$primaryNavbar->addChild('Support Center')->setOrder(30);
		$primaryNavbar->getChild('Support Center')->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('http://www.google.com');
	}
});

YRFXqGK.png

3. is going to be a label change using either Language Overrides....

$_LANG['navsupport'] = "Support";

ot0fdfm.png

changing that string will rename the parent of both the sidebar and the loggedin support navbar parent menu.

or setLabel... the other hooks will show you how to do that.

  • Like 1

Share this post


Link to post
Share on other sites

How do we add another external link like Shop to the NavMenu in the client area which should probably be here? I tried it once but I needed to restore because I got some error. 😞GRS6zWm.png

Share this post


Link to post
Share on other sites
17 minutes ago, Mauwiks said:

How do we add another external link like Shop to the NavMenu in the client area which should probably be here?

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) {
	
	if (!is_null($primaryNavbar->getChild('Store'))) {
		$primaryNavbar->getChild('Store')->addChild('newproduct1')->setLabel('My New Product Link')->setURI('http://www.google.com')->setOrder(25);
	}
});

Y597XDV.png

i'm assuming that you didn't want to get rid of the divider that you highlighted - though if you did, then that's just uses a removeChild... the same as removing any other child item.

the value within ->setOrder determines where the new link will be added... if you made it 1, it would be before "Browse All"; if you made it 1000, it would likely be at the bottom of the dropdown... anywhere between just requires you to enter different values until you have it in the position that you want it.

Share this post


Link to post
Share on other sites

Great, thanks!

I just want it to be below the browse all. Modifying the code above such as setorder shall work right?

Share this post


Link to post
Share on other sites
Just now, Mauwiks said:

I just want it to be below the browse all. Modifying the code above such as setorder shall work right?

yeah, just play with the value... if memory serves, anything over 10 should put the link after browse all.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines