Liens d'en-tête personnalisés

:discourse2: Summary Custom Header Links allows you to easily add custom text-based links to the header.
:eyeglasses: Preview Preview on Discourse Theme Creator
:hammer_and_wrench: Repository Link https://github.com/discourse/discourse-custom-header-links
:open_book: New to Discourse Themes? Beginner’s guide to using Discourse Themes

Install this theme component

Features

Desktop

Mobile

(due to very limited space I don’t recommend adding more than one link on mobiles)


Settings

Name Description
custom header links Custom links to be displayed in the header
links position Note that when links are displayed on the left, they’re automatically hidden while scrolling within topics to make room for the title

Adding links is straightforward. Every link needs 6 items. You enter comma delimited values in this order:

link text, link title, URL, view, target, hide on scroll

Link text: the text for the link.
Link title: the text that shows when the link is hovered.
URL: The path for the link (can be relative).
View: vdm = desktop and mobile, vdo = desktop only, vmo = mobile only.
Target: blank = opens in a new tab, self = opens in the same tab.
Hide on scroll: remove = hides the link when the title is expanded on topic pages keep = keeps the link visible even when the title is visible on topic pages.

If you’re not sure what hide on scroll does, here’s an example:

Most Liked and Privacy are set to keep and so they remain visible. The other links are set to remove, and so are hidden when the title expands in the header. This only affects topic pages.

Links position: This setting allows you to change the default layout so links will appear on the left near the logo instead of on the right. Note that when positioned to the left, links will automatically be hidden when scrolling within topics to make room for the topic title.


:discourse2: Hosted by us? Theme components are available to use on our Standard, Business, and Enterprise plans.

82 « J'aime »
How can I add custom hamburger menu
Header Submenus
Structuring a multilingual community
Control CSS based on user's logged in state
Display StatusPage status on as a header link
Custom Header Links (icons)
Looking for a freelancer to implement a custom Discourse theme (based on an existing mockup)
Add a global header between Discourse & Website
How to make custom setting type
Is it possible to have users' job titles next to their names on posts?
Link to find all deleted posts by all users in a particular period
Dropdown links in existing Header
Insert Link to External Website
Is anyone here using their Discourse instance as their entire website?
How to fire on every footer load (or page load?)
Custom links above header bar
Custom Header Links (icons)
Pre seeded posts all missing - Missing Terms of Service, FAQ and Privacy pages
Dropdown header links in the existing Header
Add a "curated personal learning" page for users
Redirect search icon to search page
Possible to change main logo URL?
2021: The Year in Review
How to add breadcrumb?
How to add contact us page?
Navigation bar above all post
Adding link to blog on main page
Customizing your site with existing theme components
Show "new topic" when not logged in
How can I add a new button to the topbar?
⬇️ Dropdown Header
How to fix logo size?
Links into the header block
Customize the header with links, icons, or menus
Privacy Policy does't meet Google's requirements
Customize Your Site Branding
Nextcloud support
How to override the site-header.hbs file from custom theme?
Sidebar link / top button to PM admin
Toolbar under site header per category
Privacy Policy does't meet Google's requirements
Link buttons on the top disappear when scrolling around the site
Disclaimer section on the "about" page
What Themes are being used for these Discourse forums?
Add button in header for logged in users
Use decorateWidget to add text link to header
[PAID] Expert Wanted for Forum Redesign
Add social media handles on home page
Create hyperlink from home logo
Configure a custom sidebar link to open in a new tab
2023: The Year in Review
Modifying Header
Fully Theme
Visiting /admin/upgrade may lead to a server error
How do I go about making a very customized theme?
How to Integrate a Custom Plugin in discourse UI
Embedding a whole Discourse forum on another site in an <iframe>
Memberstack + Webflow + Discourse OpenID Connect
Custom website header with forum
Custom Header Links (icons)
Brave default Theme
Why does the logo navigate to Discourse home not main site home
Structuring a multilingual community
How to make sidebar sticky?
Forum navbar is repeating
Best place(s) to link back to a non-forum homepage?
Adding a header link for Guests Only
Adding my Nav into the header bar
Link on Top header to Go to Home page of main site
How to finely scroll out custom header?
Can I add a icon and link back to my homesite at the top bar
Header Submenus
Custom Header links was automatically hide when scrolling topic page contents
Link behavior inconsistent
Upcoming Header Changes - Preparing Themes and Plugins
How to add a "button" which composes a pre-filled topic
Where to place project external URL?
Change destination of logo link
External header links are not opening in a new tab
How to split the forum into two main parts (general/groups) and how to display only subcategories I can create a new post in?
Add secondary url / embed into Wordpress
"An empty string is not a valid JSON string" when updating theme component #2
How can I add a button to the header?
Showing categories statically above most recent posts
How to add a button to the header area?

don’t know if this has been suggested, tried reading back but couldn’t find it.

was thinking that maybe adding the ability to create “sub-links” thus creating the idea of a list that you could edit (text color, background hover etc.) to get results similar to what zoom has

8 « J'aime »

the links that have the arrow to the right like developer means that it has “sub-links”

1 « J'aime »

Is it possible to add some basic dropdown menu to an any item?

I couldn’t create a dropdown menu with “Custom header links”. It seems Zoom did that. I reviewed their dropdown menu via console, but I couldn’t figure out how they interfere with the html of this component for adding dropdown to any item.

Is there a way to add this dropdown to item? @Johani

<div id="dropdown">
  <a title="Zoom Developer Documentation" href="https://marketplace.zoom.us/docs" target="_blank">Developer</a>
  <span class="caret"></span>
  <div class="dropdown-content">
    <a title="Zoom API Docs" href="https://marketplace.zoom.us/docs/api-reference/introduction" target="_blank">API</a>
    <a title="Zoom SDK Docs" href="https://marketplace.zoom.us/docs/sdk/native-sdks/introduction" target="_blank">SDK</a>
    <a title="Zoom Developer Blog" href="https://medium.com/zoom-developer-blog" target="_blank">Blog</a>
    <a title="Zoom Developer Changelog" href="https://marketplace.zoom.us/docs/changelog" target="_blank">Changelog</a>
    <a title="Zoom Developer Survey" href="https://docs.google.com/forms/d/e/1FAIpQLSeJPLhNuxjtkxyyV276R8S_nYz99fpMbbS8VWkC8Hwi7-2Byg/viewform" target="_blank">Survey</a>
  </div>
</div>
5 « J'aime »

Has anyone run into any issues with links not opening when setting links position to “left”?

Links work on Preview but not when I apply it to a theme.
Right alined links work fine though.

1 « J'aime »

Hi! Thanks for creating this.
Is it possible to add an SVG before the text link? If so - how?

1 « J'aime »

Have you found a solution for this? I am look for the same solution.

6 « J'aime »

how can the title convert **formatting code** into actual formatting? also how about Font Awesome icons before the text?

2 « J'aime »

Could be possible to add a flag to show or hide links as specific groups of users?

3 « J'aime »

Is there a way this theme component can allow for dropdown navigation? That means, when I hover over a header link, it has sub-items that appear underneath it. I know that this can be done via html/css as shown here:

2 « J'aime »

Thank you for creating this component!
One question and potentially a feature request: can we show a specific link for a specific group?
For example, if a user is in group customers I’d like to show a link to the customer’s control panel, if a user is in group workers I’d like to add a link to a different panel.
I think this would be a very useful feature.
The group name could be the last (optional) parameter.

2 « J'aime »

Merci pour ça ! Je viens de le trouver après avoir essayé diverses autres bannières et composants. C’est exactement ce dont j’ai besoin !

Une demande/suggestion : possibilité de réorganiser les liens. Je viens d’en créer plusieurs et j’ai réalisé que j’aimerais en ajouter un en haut. Maintenant, je vais devoir tous les copier-coller manuellement, ce qui est en fait assez fastidieux car ils continuent de synchroniser/mettre à jour d’autres entrées au fur et à mesure que je les copie vers le bas.

La fonction glisser-déposer ou des boutons haut/bas serait très utile pour les futurs utilisateurs (ou les futures modifications).

4 « J'aime »

[quote=“Nick_Chomey, post:131, topic:90588”]
Le glisser-déposer ou les boutons haut/bas seraient très utiles pour les futurs utilisateurs (ou les futures modifications).
[/quote]Vous pouvez déjà manipuler l’ordre très facilement avec quelques lignes de CSS puisque nous utilisons la propriété flex.

Par exemple :

  • Ordre par défaut
    image

  • Ordre personnalisé
    image

Exemple CSS :

.custom-header-links li {
  &:nth-child(1) {
    order: 3;
    background: red;
  }

  &:nth-child(2) {
    order: 1;
    background: green;
  }

  &:nth-child(3) {
    order: 2;
    background: yellow;
  }
}
5 « J'aime »

@Nick_Chomey Je me suis souvent retrouvé à devoir faire cela, non seulement pour ce composant de thème, mais pour de nombreux autres composants de thème qui utilisent le réglage type: list. J’avais l’intention de soumettre une demande de fonctionnalité auparavant, mais j’ai complètement oublié, mais puisque vous me l’avez rappelé, j’en ai ajouté une ici :

3 « J'aime »

@dax Merci ! Je n’avais aucune idée que c’était possible !

@keegan Ça a l’air super, j’espère que ça sera ajouté à un moment donné !

2 « J'aime »

Je cherche la même solution, avez-vous trouvé comment ils ont fait ça ?
Merci !

1 « J'aime »

Salut @Johani
Merci d’avoir créé un composant aussi génial !

Est-il possible qu’un lien ne soit visible que si l’utilisateur est connecté ?
Ce sera un lien externe.

1 « J'aime »

Salut @andreas_can, bienvenue sur Meta :wave:

Ce composant ajoute une classe CSS à chaque lien en fonction de son texte. La classe ajoutée est identique au texte que vous donnez au lien, sauf que les espaces sont remplacés par un trait d’union (-) et que le texte est mis en minuscules. Ensuite, la chaîne -custom-header-links est ajoutée à la fin.

Donc, si vous ajoutez un lien avec le texte

privacy

alors l’élément de lien aura la classe

privacy-custom-header-links

Si le texte de votre lien est

Visit Shop

alors la classe CSS serait

visit-shop-custom-header-links

Vous connaissez donc maintenant la classe ajoutée à chaque lien. Revenons à votre question.

Discourse ajoute une classe CSS à la balise <HTML> lorsque l’utilisateur n’est pas connecté. Cette classe est

anon

Vous pouvez donc l’utiliser pour masquer certains liens pour les utilisateurs qui ne sont pas connectés. Disons que j’ai un lien avec le texte

Customer Support

et que je ne veux pas qu’il apparaisse aux utilisateurs qui ne sont pas connectés.

J’ajouterais alors ce CSS

.anon {
  .customer-support-custom-header-links {
    display: none;
  }
}

dans l’onglet common > CSS de mon thème principal.

Cela masquera ce lien particulier pour les utilisateurs qui ne sont pas connectés.

11 « J'aime »

Merci pour cette réponse rapide et complète !
C’est exactement ce que je cherchais.

Je vais essayer :slightly_smiling_face:

3 « J'aime »

Notez que la propriété CSS display: none; masque uniquement le lien dans le rendu du navigateur, mais il est toujours entièrement visible pour quiconque consulte le code source de la page, ainsi que pour les robots d’exploration et les moteurs de recherche.

3 « J'aime »