Nerdmind/Blog

Open Graph Meta Tags for Total Facebook and Twitter Mastery?

Closed this issue · 2 comments

Is it possible to create a way (perhaps user input in the 'Create Post') to enter data for each new page to include Open Graph meta tags for Facebook and Twitter? I see there is a small bit of the code but it would be nice to be able to manually insert it. as with the slug.

Hi. Thanks for your input. There is already an argument functionality (see wiki) which you can use to pass "key->value" parameters to the page, post or user template, but they are sadly not available in the main template (html/main.php) which contains the <head> tag for the Open Graph information.

This is a problem. I'll keep you informed if I find a simple way to make this possible without adding native fields for this purpose to the content editor (native input fields for the OpenGraph tags would make the content editor bigger and not all users want to use the Open Graph tags).

Hi. I may have a solution for you. As you see in the last commit 95b3eef, you have now the possibility to access data of the current page, post or user directly from the main.php template file. For example, if you want to add additional <meta> tags for a specific post, you can do it like this:

Edit your post and insert OPENGRAPH_FOOBAR=Value into the argument field. Then modify the main.php file from your custom template and insert something like this between the <head> tags:

<?php if(isset($TYPE) AND $TYPE === 'POST'): ?>
	<?php if(isset($POST['ARGV']['OPENGRAPH_FOOBAR'])): ?>
		<meta property="og:foobar" content="<?=$POST['ARGV']['OPENGRAPH_FOOBAR']?>" />
	<?php endif; ?>
<?php endif; ?>

I would be glad if you give feedback on whether this solution has helped you.