I'm using this code in start.php of my theme and it works fine.
function mysite_init() {
elgg_unregister_menu_item('topbar', 'elgg_logo');
$logo_url = elgg_get_site_url() . "mod/mysite/img/topbar-logo.png";
elgg_register_menu_item('topbar', array(
'name' => 'my_logo',
'href' => 'http://www.mysite.com/',
'text' => "<img src=\"$logo_url\" alt=\"My logo\" width=\"280\" height=\"40\" />",
'priority' => 1,
'link_class' => 'elgg-topbar-logo',
));
}
I'm wanting to remove some other items within the topbar, so have included these lines:
elgg_unregister_menu_item('topbar', 'profile');
elgg_unregister_menu_item('topbar', 'friends');
elgg_unregister_menu_item('topbar', 'messages');
However, they still remain in the topbar. What am I doing wrong?
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Nikolai Shcherbin@rivervanrain
Nikolai Shcherbin - 0 likes
- Team Webgalli@webgalli
Team Webgalli - 0 likes
- Juho Jaakkola@juho.jaakkola
Juho Jaakkola - 0 likes
- Juho Jaakkola@juho.jaakkola
Juho Jaakkola - 0 likes
- Burgs@burgs
Burgs - 0 likes
- Juho Jaakkola@juho.jaakkola
Juho Jaakkola - 0 likes
- Juho Jaakkola@juho.jaakkola
Juho Jaakkola - 0 likes
- Burgs@burgs
Burgs - 0 likes
- Nikolai Shcherbin@rivervanrain
Nikolai Shcherbin - 0 likes
You must log in to post replies.It's wrong way!
You need to change the mod's start.php
Ex., 4 messages:
Go 2 mod/messages
Edit start.php as:
Do it in other mods/plugin if u need :)
@RVR : Burg has done it the correct way. Thats the purpose of using plugin hooks. If we modify the start.php in individual files then we have to modify it each and everytime we do an upgrade of Elgg. So its better to use a common tweak plugin for your system and then make all the modification in your plugin.
@ Burg, can you paste the complete code here.
@Burgs
I think those three functions do not work because they are executed before the menu items are registered.
For example the friends menu item is registered on "pagesetup, system" event and your mysite_init is run on "system, init" event which is run before the pagesetup.
You can try something like this instead:
Here's the same for removing multiple items:
@RVR - Fantastic avatar
@JJ - Here's my full file, where would I insert your code exactly?
<?php
/**
* Elgg demo custom index page plugin
*
*/
elgg_register_event_handler('init', 'system', 'mysite_init');
function mysite_init() {
// Extend system CSS with our own styles
// elgg_extend_view('css/elgg', 'mysite/css');
// Replace the default index page
//elgg_register_plugin_hook_handler('index', 'system', ' mysite');
elgg_unregister_menu_item('topbar', 'elgg_logo');
$logo_url = elgg_get_site_url() . "mod/mysite/img/logo-top.png";
elgg_register_menu_item('topbar', array(
'name' => 'my_logo',
'href' => 'http://community.mysite.com/',
'text' => "<img src=\"$logo_url\" alt=\"My logo\" width=\"126\" height=\"40\" />",
'priority' => 1,
'link_class' => 'elgg-topbar-logo',
));
}
Alternative way:
If using this, make sure that your plugin is located in the plugin list after the plugins which register the items you want to disable.
@Burgs
Insert the elgg_register_plugin_hook_handler() in the mysite_init() function and the custom_topbarmenu_setup() function anywhere in your plugin's start.php
@TeamW - Thanks
@JJ - It works... thanks and to clarify here's my complete code...
<?php
/**
* Elgg demo custom index page plugin
changed by nawtnet
*
*/
elgg_register_event_handler('init', 'system', 'nawtnet_init');
function nawtnet_init() {
// Extend system CSS with our own styles
// elgg_extend_view('css/elgg', 'nawtnet/css');
// Replace the default index page
//elgg_register_plugin_hook_handler('index', 'system', 'nawtnet');
elgg_unregister_menu_item('topbar', 'elgg_logo');
$logo_url = elgg_get_site_url() . "mod/nawtnet/img/logo-top.png";
elgg_register_menu_item('topbar', array(
'name' => 'my_logo',
'href' => 'http://community.canyonlets.com/',
'text' => "<img src=\"$logo_url\" alt=\"My logo\" width=\"126\" height=\"40\" />",
'priority' => 1,
'link_class' => 'elgg-topbar-logo',
));
elgg_register_plugin_hook_handler('register', 'menu:topbar', 'custom_topbarmenu_setup');
}
function custom_topbarmenu_setup ($hook, $type, $return, $params) {
$remove = array('profile', 'friends', 'messages');
foreach($return as $key => $item) {
if (in_array($item->getName(), $remove)) {
unset($return[$key]);
}
}
return $return;
}
@Burgs
;)
@Burgs
@Juho Jaakkola
I tried your complete code.. It works!