Add custom field information to source meta data

I try to add information from a custom field into the metadata in the source code. While searching for the solutions I found some. As I am not really an expert I ask you guys. I want to add information for a Digital Object Identifier (DOI) from a custom field to the source code so that the Search Engine of Altmetrics can find it. Necessary meta tags are:

  • Identifier (e.g. citation_doi)
  • Title (e.g. citation_title)
  • Author (e.g. citation_author)
  • ISSN - if applicable (e.g. citation_issn)

Finally, it should look like this in the Page Source:

meta name="citation_title" content="A qualitative study" /
meta name="citation_journal_title" content="Accountability in Research" /
meta name="citation_author" content="David Shaw" /
meta name="citation_doi" scheme="doi" content="10.1080/08989621.2017.1413940" /
meta name="citation_source" content="https://doi.org/10.1080/08989621.2017.1413940" /

Some more comments: the DOI is unique for every blogpost. If you want to see the page look here: https://elephantinthelab.org/ I could really need help, especially in which .php-File I should put the information. I am also happy if you know a plugin which does the job. All SEO plugins I tried are not flexible enough. Thank you, much appreciated!

Topic wp-blog-header.php single post-meta custom-field Wordpress

Category Web


You will first need to add some metaboxes to your posts. This has been answered a lot, and there are many posts on the internet about is, such as this full guide.

After adding metaboxes, you can hook into the wp_head action hook and output your metadata. Here's a simple piece of code that goes into your theme's functions.php file:

add_action ( 'wp_head', 'add_my_metadata' );
function add_my_metadata() {
    if ( is_single() ) {
        ?><meta name="citation_title" content="<?php echo get_post_meta( get_the_ID(), 'meta_key_here', true ); ?>" /><?php
    }
}

Make sure that your theme has the wp_head() function inside its header.php file, so the action hook can actually print the above code.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.