News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Meta tags issue

Started by Julius_2000, February 25, 2023, 06:33:46 AM

Previous topic - Next topic

Julius_2000

Hi, this is sort of a crossover with the Optimus mod topic but I wasn't sure where exactly to post this.

As far as I understand, SMF comes with a basic meta tag feature for the board descriptions for social media cards. Before installing the Optimus mod, I noticed that there's no real site description for the index page (only the forum name), therefore (among other things) I installed Optimus.

But then I noticed that even though the forum would now get a proper site description I checked with sites like HeyMeta or the Facebook debugger, the individual description for each board would not show in those meta cards. Instead, only the general forum description set in Optimus would get displayed. So I added this line to the Index.template.php after the meta function.

echo ' <meta name="description" content="', $context['description'],'" />';
This works, as in I'm getting the board description again, but now I'm also getting an error message, telling me that there's an undefined index for "description". So I guess I incorrectly use the $context variable.

Is there a way to do that?

Edit: I also notice that on boards or the index page, there's no meta tag in the form of property="og:" in the html head. But when I'm in the admin section they are there. So for instance in Modcenter I get both
<meta name="description" content="Moderation Center">
<meta property="og:description" content="Moderation Center">

But on a board I only get
<meta name="description" content="my Forum description">
<meta prefix="og: http://ogp.me/ns#" property="og:description" content="my Forum description">
While the former one is also apparently a copy of my description set up in Optimus. (even though there's a seperate Optimus specific meta tag already there, starting with "prefix...")

)

live627

Quote from: Julius_2000 on February 25, 2023, 06:33:46 AMBut then I noticed that even though the forum would now get a proper site description I checked with sites like HeyMeta or the Facebook debugger, the individual description for each board would not show in those meta cards. Instead, only the general forum description set in Optimus would get displayed. So I added this line to the Index.template.php after the meta function.

Code Select Expand
echo ' <meta name="description" content="', $context['description'],'" />';
This works, as in I'm getting the board description again, but now I'm also getting an error message, telling me that there's an undefined index for "description". So I guess I incorrectly use the $context variable.
then we need isset()

if (isset($context['description'])) echo ' <meta name="description" content="', $context['description'],'" />';

Julius_2000

Thank you! That works. Much appreciated!

Advertisement: