News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Open Graph tags only on home page

Started by lamerator, February 02, 2016, 04:02:03 AM

Previous topic - Next topic

lamerator

Hello,

And sorry for my bad English.

I want to put this OG tags only on home page of my forum:

<meta property="og:title" content="alabala alabala" />

<meta property="og:description" content="alabala alabala" />


How can i do this?

Regards!

Kindred

add that code into your theme's index.template.php, just above the closing </head> tag
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Antes

to be clear here, index.template loads in every page so no don't put that code to index.template (if you insist on loading OG tags only on boardindex), on the other hand OG tags should be on every page, so I suggest taking a quick look here and apply the same for your forum.

https://github.com/SimpleMachines/SMF2.1/blob/release-2.1/Themes/default/index.template.php#L110-L116

lamerator

Thanks for the answers!

I'm looking for php code who puts meta tags only on index page. For example in wordpress that code is:

<?php if ( is_home() ) { ?>
<meta name="description" content="My Description" />
<?php ?>


Sorry again for my bad English!

Kindred

good catch Antes...

lamerator,
why only on the main landing page?

However, if so - then Antes is correct, the code would have to be added in boardindex.template.php


(side note, moving this to coding, since it's not really support)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

lamerator

Quote from: Kindred on February 02, 2016, 10:56:08 AM
good catch Antes...

lamerator,
why only on the main landing page?

However, if so - then Antes is correct, the code would have to be added in boardindex.template.php


(side note, moving this to coding, since it's not really support)

Kindred, because I don't want all forum pages to use same OG meta tags. My idea is only home page to have OG tags - title and description.

Kindred

well, if you don't all pages to have the SAME metatags, then you should look at what Antes linked to, since that makes the metatags dynamic based on the page content.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

saurabh1938

Quote from: Antes on February 02, 2016, 09:39:29 AM
to be clear here, index.template loads in every page so no don't put that code to index.template (if you insist on loading OG tags only on boardindex), on the other hand OG tags should be on every page, so I suggest taking a quick look here and apply the same for your forum.

https://github.com/SimpleMachines/SMF2.1/blob/release-2.1/Themes/default/index.template.php#L110-L116

I know I am opening an old topic but it is very important for me to know, I am banging my head over this for very long but not getting a solution.

Based on above comment I have added this code to my Index.template.php of the current theme of my forum
// Some Open Graph?
echo '
<meta property="og:site_name" content="', $mbname,'">
<meta property="og:title" content="', $context['page_title_html_safe'],'">
', !empty($context['canonical_url']) ? '<meta property="og:url" content="'. $context['canonical_url'].'">' : '',
!empty($settings['og_image']) ? '<meta property="og:image" content="'. $settings['og_image'].'">' : '','
<meta property="og:description" content="',!empty($context['meta_description']) ? $context['meta_description'] : $context['page_title_html_safe'],'">';


I am using 2.0.11 but still nothing has happened and when I share my content still no image is fetched and just plane title and description are being picked up. Please tell me what I am doing wrong, do I need to add the same code to default theme also? do I need to add some more code anywhere to make this code workable.

Its a request to please help me on this.
Visit my forum : www.gotripperz.com

Advertisement: