• Dev
  • How to add meta tags to <head>

I'm searching for a proper way to add some meta tags to the <head> HTML section. I couldn't find the proper way to do this into documentation and also couldn't find an extension example wich i can follow.

Maybe someone can give me some hints about how to do this. Thanks in advance.

    Zeokat just go to ADMIN > appearance > custom Header.
    i try add meta tag for og, work for me.
    but just change title and description.

      FebriTriHarmoko Yes, i'm trying to add open graph to posts, because when i share them on social networks the result is ugly as hell ?

      With your advice i can't solve the issues, because you need to add differente og data to each post/conversation. Also find the image, description, etc...

      Anyway thanks for your advice but it not solves the issue. I need to write an extension for that and is what i'm searching.

        Now i need to get discusssion title and contents of the discussion (contents of first post only).

        Any idea/example about how to to do this...?

          Zeokat

          looks like the controller saves the discussion inside the view here so you might be able to read this attribute for discussion pages https://github.com/flarum/core/blob/v0.1.0-beta.7/src/Forum/Controller/DiscussionController.php#L89

          Also both request and controller aree available inside the event so you should be able to use methods from DiscussionController or your own implementation to find out the discussion https://github.com/flarum/core/blob/v0.1.0-beta.7/src/Event/ConfigureWebApp.php#L25

            a year later

            Zeokat Yes, i'm trying to add open graph to posts, because when i share them on social networks the result is ugly as hell 😄

            Have you figured it out yet? We have a big Facebook group with over 80k members where we want to promote our forum, but not doing it because of this. 😕 It doesn't seem to work and we've tried everything mentioned here and in other discussions.

              user1993 this should work:

              use Flarum\Extend;
              use Flarum\Frontend\Document;
              
              return [
                  (new Extend\Frontend('forum'))
                      ->content(function (Document $document) {
                          $document->head[] = 'HEAD HTML HERE';
                      })
              ]

                OrdinaryJellyfish The thing is, Facebook debugger shows that these meta tags already exist somewhere. It's just showing the logo of the site when you share on Facebook or Twitter. Even Flarum's is like this.

                  user1993 The only meta tags Flarum adds by default is the <meta name="description"> one. Facebook uses OpenGraph, I think, you'd need to add this:

                  <meta property="og:description" content="bleh bleh bleh">

                  Of course, there are more tags you can use to improve your SEO, such as other OpenGraph tags, and Facebook/Twitter/etc specific tags.

                    OrdinaryJellyfish Already tried everything, even the OpenGraph tags suggested by Facebook. After a few days, still shows the logo of the site and not the image we have specified.

                    I understand that this is not a priority at the moment, but do people, especially in production not care about how it appears on social media?

                      user1993 Huh, well, I don't know then. SEO is pretty frustrating at times... It is possible that you're not adding the meta tags to the right place, or they're just not showing up.