Add button to top menu

I want to add a button (with a different color) to the top menu, and if possible align right
How can i do this ?

1 Like
7 Likes

Almost, but i want to have this button: Premium

Check here: How to add header menu links

1 Like

check, did this but there is no button …

You’ll have to customize a bit with HTML / CSS to get exactly the look you’re going for. If you have a reference button you want to copy you can often get most of the way there by inspecting using something like Chrome web tools and copying existing styles. Lots of tutorials you can follow + modify as well! Definitely a bit of a learning curve but imo fun to figure out how this stuff works :slight_smile:

3 Likes

Screenshots would be really helpful. It is hard to tell if your theme component is just not active or if you put the code in the wrong place.

1 Like

Show us what you’ve got so far and we’ll help you tweak it. We’re flying blind a bit here…

2 Likes

this is the forum: https://forum.webwinkelcommunity.nl/
and instead of the bleu arrow icon i want a button with Premium (or Donateur)

Try changing the following

    api.decorateWidget('header-icons:before', function (helper) {
        return helper.h('li', [helper.h('a#home-button.icon', {
            href: 'https://forum.webwinkelcommunity.nl/t/wordt-donateur/2171/1',
            title: 'Wordt Donateur'
        }, helper.h('i.fa.fa-arrow-circle-up.home-button-icon.d-icon'))]);
    });

to

    api.decorateWidget('header-icons:before', function (helper) {
        return helper.h('li', [helper.h('a#home-button', {
            href: 'https://forum.webwinkelcommunity.nl/t/wordt-donateur/2171/1',
            title: 'Wordt Donateur',
            text: 'Wordt Donateur'
        })]);
    });

With the following CSS

a#home-button {
    border: 1px solid #000;
    padding: 5px;
    border-radius: 3px;
    position: relative;
    display: block;
    margin-top: 5px;
}

Screenshot:
image

9 Likes

This should do it: ( demo: https://www.mcrides.co.nz I have a “Weather” link )
You’ll need to style it with css.
customize->theme-></body

<script>

  Discourse.ExternalNavItem = Discourse.NavItem.extend({
    href : function() {
      return this.get('href');
    }.property('href')
  });

  I18n.translations.en.js.filters.premium = { title: "Premium", help: "Premium account" };

  Discourse.NavItem.reopenClass({
    buildList : function(category, args) {
      var list = this._super(category, args);
      if(!category) {
        list.push(Discourse.ExternalNavItem.create({href: '/my/link.html', name: 'premium'}));
      }
      return list;
    }
  });

 </script>
1 Like

But that adds it to the Navigation, not the header…

But I guess it isn’t obvious which he wants, as his initial posts says “top menu” which refers to the navigation, but his screenshot and example of where his icon is… is in the header.

My example adds to header menu, not to navigation

You are opening the NavItem class and your Weather example is on the navigation…

oh :blush:

Maybe he wants

<script type="text/discourse-plugin" version="0.4">
api.decorateWidget('header-icons:before', helper => {
    return [
            helper.h('li', [
            helper.h('a#premium-button.icon', {
                href: '/link.html',
                title: 'Premium Content'
            }, helper.h('i.fa.fa-cloud.premium-button-icon.d-icon')),
        ])
    ];
});
</script>
2 Likes

Close, that is almost what he has now, I provided code that puts text there and makes it more “button-ish” (just a few posts up) :wink: So now he has both … one of the two should do what he wants.

4 Likes

Great @cpradio that works, many thanks!

Hi,

  1. How and where do you add the icons? I like to use external icons instead of fa
  2. I’m trying to open an external link. Is there a way to add a target so that we use a different window?

Thanks