exampleHeaderLinks.php, modifyHeaderLinks.php. header_links no longer working in 3.+, stuck at 2.6+

6 posts by 2 authors in: Forums > CMS Builder
Last Post: September 11, 2018   (RSS)

By gkornbluth - September 6, 2018

Hi All,

I've used exampleHeaderLinks.php (code below) on a few old sites (running 2.64) to modify what links members see when they log in to the management interface.

I'd love to update those sites to 3.14, but since the header_links hook has been deprecated, I'm stuck.

Any fixes?

Thanks,

Jerry Kornbluth

______________________________________________

<?php
/*
Plugin Name: Example header links
Plugin URI:
Description: Example of how to add links to header bar
Author:
Version: 1.0
Author URI:
*/

// NOTE: If you update this file be sure to RENAME it so it doesn't get overwritten when you upgrade!
// NOTE: Rename both the file and the function name 'plugin_addHeaderLinks' to something unique

addFilter('header_links', 'plugin_addHeaderLinks');

//
function plugin_addHeaderLinks($html) {

// add links at the beginning
$preLinks = '';
$preLinks .= "<a href='http://www.google.com/'>Google</a> | ";

// add links at the end
$postLinks = '';
$postLinks .= " | <a href='http://www.yahoo.com/'>Yahoo</a>";

//
$html = $preLinks . $html . $postLinks;
return $html;
}

?>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By daniel - September 6, 2018

Hi Jerry,

If you check out the latest version of the Modify Header Links plugin (https://www.interactivetools.com/add-ons/modify-header-links/) it should contain new examples for how to modify header links in CMSB v3.

Let me know if you have any questions!

Thanks,

Daniel
Technical Lead
interactivetools.com

By daniel - September 7, 2018 - edited: September 7, 2018

Hi Jerry,

1) If I had a series of links that I wanted to show at the beginning, lets say:
3) Would I add another series of links to the end in a similar way by creating a $newmenu2 array and then changing array_push($menuArray, $newMenu); to array_push($menuArray, $newMenu2);

For adding these external links at the beginning, you would use something like this:

$newMenu = [
  'menuName' => 'The Free Pixlr On-Line Image Editors &gt;&gt;',
  'menuType' => 'custom',
  'link' => "http://pixlr.com/express/",
  'isSelected' => false,
  'linkTarget' => '_blank',
  'visibility' => 'showAlways',
  'br_after' => true,
];
array_unshift($menuArray, $newMenu);

$newMenu = [
  'menuName' => 'How to Use Pixlr Express &gt;&gt;',
  'menuType' => 'custom',
  'link' => "http://www.elleschorrphotography.com/using-pixlr.php",
  'isSelected' => false,
  'linkTarget' => '_blank',
  'visibility' => 'showAlways',
  'br_after' => true,
];
array_unshift($menuArray, $newMenu);

As you can see, you can keep using the $newMenu variable name - simply call either array_unshift($menuArray, $newMenu) (add to the beginning) or array_push($menuArray, $newMenu) (add to the end) after each option array definition to add it to the menu.

2) How would I set the following code to TRUE

This is only necessary for links that point to pages within CMSB and is mostly done automatically. You would just need to make sure that the value in that line matches the "menu=" value in the link option. For example:  

'link' => "?menu=example",
'isSelected' => (@$_REQUEST['menu'] == 'example'),
     

Let me know if there's anything else I can help with.  

Thanks,

Daniel
Technical Lead
interactivetools.com

By gkornbluth - September 7, 2018

Thanks Daniel,

Makes much more sense now.

I'll write this up and share it as a recipe in my CMSB Cookbook.

Don't know if you've  had a chance to look over the cookbook. When you do i would appreciate any suggestions.

I'll look out for your free trial membership ( http://www.thecmsbcookbook.com/trial.php ) and convert it to a complementary lifetime membership as I have for everyone else at Interactive Tools.

Welcome to the group.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By daniel - September 11, 2018

Hey Jerry,

I've just signed up, I'll definitely check it out when I've got some time.

Thanks!

Daniel
Technical Lead
interactivetools.com