0

Better title might be 'How to set the menuItem object 'link' property?'

I've used menu overrides for a variety of purposes such as changing layout and styling etc but would now like to change the href of a menu item with a certain alias.

By default, the attributes are built like so:

$attributes = array();

if ($item->anchor_title)
{
    $attributes['title'] = $item->anchor_title;
}

if ($item->anchor_css)
{
    $attributes['class'] = $item->anchor_css;
}

if ($item->anchor_rel)
{
    $attributes['rel'] = $item->anchor_rel;
}

Ideally I'd like something like:

switch ($item->alias) {
  case 'specificAlias':
    $attributes['href'] = "www.desired_link.com";
    $linktype = $item->title;
    break;
  default:
    $linktype = $item->title;
}

I've also tried this:

$item['link'] = "www.theDesiredLink.com";

I will be working out the URL dynamically which is why I can't set it manually for the menu item.

1

Need to use the 'flink' property in the $item object.

Full solution was as follows:

switch ($item->alias) {
  case 'a specific alias':
    $item->flink = "the desired URL";
    $linktype = $item->title;
    break;
  default:
    $linktype = $item->title;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.