Reload page body when clicking a link in a custom header

Hi.
Like many people, I’ve set up a custom header on top on my Discourse forum:
image

I wanted my top menu identical to my Wordpress site (I use WP-Discourse), this is why I kept the “Forum” menu item.

I would like this link to reload the forum body when clicked on, exactly when we click on the logo from the regular discourse header bar.

How can I achieve this?

Do you mean reload as in cause the whole page to reload - reload the entire app - or do you just want the link to take you to the homepage within the app?

This :slightly_smiling_face:

Try setting the href of the link to "/" Like so:

<a href="/">FORUM</a>

Hi, I already tried that as well as adding data-auto-route="true" with no success.

Try something like this:

<a href="/" class="home-link">FORUM</a>

<script type="text/discourse-plugin" version="0.8.20">
$(function() {
  $("a.home-link").click(function() {
    require("discourse/lib/url").default.routeTo(
      $(event.currentTarget).attr("href")
    );
    return false;
  });
});
</script>

Where you give your link the classname home-link and run a tiny script when it’s clicked to force it to load within the app.

2 Likes

Hi, thanks for your reply.
It doesn’t work, and here’s the output code on the page source:

<script>Discourse._registerPluginCode('0.8.20', function (api) {

  $(function () {
    $("a.home-link").click(function () {
      console.log("test");
      require("discourse/lib/url").default.routeTo($(event.currentTarget).attr("href"));
      return false;
    });
  });
});</script>

I’m not sure what’s going on on your side, but I’m positive that that would work. Here’s a basic live example on theme creator:

https://theme-creator.discourse.org/theme/Johani/forum-link

3 Likes

Hi, I’ not sure what I did before but it is indeed working. Thank you very much!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.