I am creating a template from scratch for Wordpress, but I would like to change the content of the og tags according to the content of the post, ie define image title and description
Thank you in advance
I am creating a template from scratch for Wordpress, but I would like to change the content of the og tags according to the content of the post, ie define image title and description
Thank you in advance
The Guideline for Developing Themes recommendation is to separate design functionality. Things like SEO and Shortcodes do not belong in themes, because when changing theme - which happens frequently - the site loses these features, needing to be migrated from one theme to another. Even if you are developing your own theme, you will most likely develop another at some point in the future.
What's most useful when developing the theme is to follow the Themes SEO Guide (mirror) Yoast. And even being a theme developer nothing prevents create plugins that work with your themes.
That said, what the WordPress SEO plugin does is print the tags on <head>
using action hook wp_head
.
Here, I started to wipe the whole class where the plugin handles this output. You must check the other methods within the class to complete the meta tags. The code is commented out and every missing tag has the name of the method where you can check how Yoast handles each goal property
.
<?php
/**
* Plugin Name: (SOPT) OG Meta Tags
*/
add_action( 'wp_head', 'sopt_32080_head', 1 ); // Prioridade 1, imprime o antes possível
function sopt_32080_head()
{
# POST ATUAL
# as Conditional Tags como is_front_page, is_archive, is_singular, etc, cuidarão de saber qual a página atual
# http://codex.wordpress.org/Conditional_Tags
global $post;
# LINGUAGEM
echo '<meta property="og:locale" content="pt_BR" />' . "\n";
# TIPO
if ( is_front_page() || is_home() ) {
$type = 'website';
} elseif ( is_singular() ) {
$type = 'article';
} else {
// We use "object" for archives etc. as article doesn't apply there
$type = 'object';
}
echo '<meta property="og:type" content="' . $type . '" />' . "\n";
# TITULO
if ( is_singular() ) {
$title = 'Article - ' . $post->post_title;
} else if ( is_front_page() ) {
$title = 'Website - ' . get_bloginfo('name');
} else {
$title = 'Outro tipo de página';
}
echo '<meta property="og:title" content="' . $title . '" />' . "\n";
# TODO: OUTRAS TAGS
# fb:app_id ou fb:admins
// public function site_owner()
# og:description
// public function description()
# og:url
// public function url()
# og:site_name
// public function site_name()
# article:publisher
// public function website_facebook()
# ARTIGOS INDIVIDUAIS
if ( is_singular() && ! is_front_page() ) {
# article:author
// public function article_author_facebook()
# article:tag
// public function tags()
# article:section
// public function category()
# article:published_time e article:modified_time e og:updated_time
// public function publish_date()
}
# og:image
// public function image()
}