Olá! Preciso inserir novos metadados no head do html de algumas páginas para que o Google Scholar reconheça os itens do nosso repositório.
Pesquisando o código eu vi que no wp_head se encontra alguns metas pegando as informações dos metadados do repositório que criei no Tainancan, como title de cada item(página).
Minha dúvida é a seguinte:
Consigo pegar os dados de metadados do Tainacan, como autor, descrição e data que eu crie e inserir no head com alguma variable ou outro formato?
Por exemplo:
<meta name="citation_title" content="%blog_title%">
ou
<meta name="citation_title" content="<?php bloginfo('title'); ?>">
OBS: Estou usando o plugin Meta Tag Manager para add as metatags em páginas específicas, para que eu não precise alterar o wp_head.
Metas que vou inserir:
<meta name="citation_title" content="">
<meta name="citation_author" content="">
<meta name="citation_publication_date" content="">
<meta name="citation_journal_title" content="">
<meta name="citation_DC.Description" xml:lang="pt-br" content="">
<meta name="citation_pdf_url" content="">
Desde já, muito obrigado!
Olá @jefdoria !
Cara, acho que você consegue isso usando a action wp_head
, que nem é feito pelo plugin aqui:
add_shortcode( 'tainacan-dynamic-items-list', array($this, 'get_tainacan_dynamic_items_list'));
add_shortcode( 'tainacan-related-items-carousel', array($this, 'get_tainacan_related_items_carousel'));
add_action( 'generate_rewrite_rules', array( &$this, 'rewrite_rules' ), 10, 1 );
add_filter( 'query_vars', array( &$this, 'rewrite_rules_query_vars' ) );
add_filter( 'template_include', array( &$this, 'rewrite_rule_template_include' ) );
add_action( 'pre_get_posts', array($this, 'archive_repository_pre_get_posts'));
// TODO: fix the WP Title
// add_filter( 'wp_title', array($this, 'archive_repository_wp_title'), 10, 3);
add_action( 'wp_head', array($this, 'add_social_meta'), 5 );
$this->register_view_mode('table', [
'label' => __('Table', 'tainacan'),
'description' => 'The classic table display.',
'dynamic_metadata' => true,
'icon' => '<span class="icon"><i class="tainacan-icon tainacan-icon-viewtable tainacan-icon-1-25em"></i></span>',
'type' => 'component',
'implements_skeleton' => true,
'requires_thumbnail' => false
]);
Daí pra pegar os metadados em específico que vc quer pode usar as própria API interna do Tainacan. Temos um pouco da documentação dela aqui:
Se tiver dificuldade com este processo, só chamar!
1 curtida
Oi Mateus.
Eu não estou conseguindo pegar os dados do author do meu item em colocar na meta tag
O que eu tentei fazer:
public function add_social_meta() {
if ( is_single() || is_tax() || is_archive() ) {
$author = get_the_author_meta();
Estou tentando pegar a url do pdf que tem na página e colocar na metatag também, mas estou aprendendo como faz.
Sou bem leigo, mas estou conseguindo me virar.
Consegue me Ajudar?
Valeu!
Tranquilo @jefdoria vamos por parte.
Eu recomendo dar uma olhada neste arquivo como um todo:
<?php
use \Tainacan\Entities;
use \Tainacan\Repositories;
/**
* To be used inside The Loop
*
* Return the item metadata as a HTML string to be used as output.
*
* Each metadata is a label with the metadatum name and the value.
*
* If an ID, a slug or a Tainacan\Entities\Metadatum object is passed in 'metadata' parameter, it returns only one metadata, otherwise
* it returns all metadata
*
* @param array|string $args {
* Optional. Array or string of arguments.
*
* @type mixed $metadata Metadatum object, ID or slug to retrieve only one metadatum. empty returns all metadata
This file has been truncated. show original
Todas as funções presentes nele devem estar disponíveis para você chamar no seu contexto. Por exemplo, com a função tainacan_get_item()
você recebe o objeto do post do item. Se você der um var_dump nele vai poder ver quais atributos estão presentes ali, se não me engano tem um get_author_name()
dentro dele.
*/
function tainacan_register_view_mode($slug, $args = []) {
\Tainacan\Theme_Helper::get_instance()->register_view_mode($slug, $args);
}
/**
* Gets the Tainacan Item Entity object
*
* If used inside the Loop of items, will get the Item object for the current post
*/
function tainacan_get_item($post_id = 0) {
return \Tainacan\Theme_Helper::get_instance()->tainacan_get_item($post_id);
}
/**
* To be used inside The Loop of a faceted serach view mode template.
*
* Returns true or false indicating wether a certain property or metadata is
* selected to be displayed
*
* @param string|integer The property to be checked. If a string is passed, it will check against
Neste caso depende um pouco de onde está o Documento, vale testar a função tainacan_get_the_item_document_url()
*/
function tainacan_get_the_document_raw($item_id = 0) {
$item = tainacan_get_item($item_id);
if (!$item)
return;
return apply_filters('tainacan_get_the_document_raw', $item->get_document($item_id), $item);
}
function tainacan_get_the_item_document_url($item_id = 0) {
$item = tainacan_get_item($item_id);
if (!$item)
return;
return apply_filters('tainacan_get_the_item_document_url', $item->get_document_download_url(), $item);
}
function tainacan_get_the_document_type($item_id = 0) {
$item = tainacan_get_item($item_id);
Se ele for um anexo, talvez a tainacan_get_attachment_html_url()
ajude:
function tainacan_get_the_attachments($exclude = null, $item_id = 0) {
$item = tainacan_get_item($item_id);
if (!$item)
return [];
return apply_filters('tainacan-get-the-attachments', $item->get_attachments($exclude), $item);
}
function tainacan_get_attachment_html_url($attachment_id) {
return \Tainacan\Media::get_instance()->get_attachment_html_url($attachment_id);
}
/**
* @see \Tainacan\Theme_Helper->register_view_mode()
*/
function tainacan_register_view_mode($slug, $args = []) {
\Tainacan\Theme_Helper::get_instance()->register_view_mode($slug, $args);
}