citationmeta

Improves Wordpress metadata for common reference management software by using open standards

https://github.com/errotu/citationmeta

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: scholar.google
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.1%) to scientific vocabulary
Last synced: 7 months ago · JSON representation ·

Repository

Improves Wordpress metadata for common reference management software by using open standards

Basic Info
  • Host: GitHub
  • Owner: errotu
  • License: mit
  • Language: PHP
  • Default Branch: main
  • Size: 40 KB
Statistics
  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created about 3 years ago · Last pushed 7 months ago
Metadata Files
Readme License Citation

README.md

citationMeta for Wordpress

This repository contains a function to improve the quality of the metadata shown in the website’s HTML head of a Wordpress blog.

Such improvement is of particular importance for scientific blogs. The additional metadata is displayed as Highwire Press tags (inter alia recommend by Google Scholar) as well as the Dublin Core tags. When used, common reference management software, such as Zotero, can easily import the articles.

How to use

Simply add the code of the citationMeta.php to the bottom of your Wordpress theme’s functions.php (without the leading “<?php”).

Please be aware that the code probably needs to be adjusted concerning the output of authors (look for $citationAuthors and 'display_name'). As Wordpress allows only one author per post, there are many different solutions in the wild on how to add the possibility of having multiple authors per post. The current code should work with the popular CoAuthors Plus plugin.

Also, the code was created for blogs cooperating with the intRechtDok service. To provide a PDF, it retrieves the link of the PDF created by intRechtDok. If you’re not cooperating with intRechtDok, the code shouldn’t throw out any errors, but will – of course – not be able to provide any PDF.

Other custom fields which possibly need to be adjusted are 'subline' (for the subtitle - if you are using one) and 'doi' (if you have a custom field containing a DOI).

Owner

  • Login: errotu
  • Kind: user

Citation (citationMeta.php)

<?php

// Adds meta data information to the HTML header for common reference managers
add_action('wp_head', 'citationMeta');

function citationMeta(){

// Code is only executed on posts, not pages
if(is_single()):

// Add possible subtitle to the title (adjust custom field (get_field('subheadline')) if necessary)
	$subTitle = get_field('subheadline');	
	$citationTitle = get_the_title();
	if($subTitle) :
		$citationTitle = $citationTitle . ': ' . $subTitle;
	endif;

// Strip HTML tags from excerpt
	$citationAbstract = strip_tags( get_the_excerpt() );

// Get date of post, name of blog and link to post
	$citationPublicationDate = get_the_date('F j, Y'); 
	$citationJournalTitle = get_bloginfo('name');
	$citationFulltextHtmlUrl = get_permalink();
	
// Get the tags of the post	
	$tags = get_the_tags();
	$citationKeywords = '';
	if ($tags) :
  		foreach($tags as $tag) {			
			$citationKeywords = $tag->name  . '; ' . $citationKeywords; 
  		}
	
		// Special code for the Völkerrechtsblog, removing the language codes for tags	
		$citationKeywords = str_replace('[:en]','',$citationKeywords);
		$citationKeywords = str_replace('[:de]','',$citationKeywords);
		$citationKeywords = str_replace('[:]','',$citationKeywords);
	endif;

// Retrieve the authors (adjust custom field or function to retrieve the array of authors correctly)
	$citationAuthors = get_coauthors();

// Retrieve DOI if it exists (adjust custom field (get_field('doi')) if necessary)
	$doi = get_field('doi');
	$doiValid = false;

// Retrieve the PDF by intRechtDok if cooperation exists	
	if($doi) :
		$intRechtDokPDFurl = '';
		$doiJSON = @file_get_contents('https://dx.doi.org/api/handles/'.$doi);
		// Check if DOI is valid
		if(!$doiJSON == false) {
			$doiValid = true;
			$doiData = json_decode($doiJSON, true);			
			$intRechtDokURL = $doiData['values'][1]['data']['value'];		
			// Check if DOI links to intRechtDok
			if (str_contains($intRechtDokURL, 'https://intrechtdok.de/receive/')) :
				$intRechtDokID = str_replace('https://intrechtdok.de/receive/', '', $intRechtDokURL);
				$intRechtDokJSON = file_get_contents('https://intrechtdok.de/api/v2/objects/'.$intRechtDokID.'/derivates.json');
				$intRechtDokData = json_decode($intRechtDokJSON, true);
				// Check if intRechtDok returns content
				if(!$intRechtDokData == false) {
					$intRechtDokPDFtitle = $intRechtDokData[0]['maindoc'];
					$intRechtDokPDFid =  $intRechtDokData[0]['href'];
					$intRechtDokPDFurl = 'https://intrechtdok.de/servlets/MCRFileNodeServlet/'.$intRechtDokPDFid.'/'.$intRechtDokPDFtitle;
				}
			endif;
		}
	endif;
?>


<!-- Meta Data for Reference Managers: Highwire Press tags -->
	<meta name="citation_title" content="<?php echo $citationTitle ?>">
	<meta name="citation_abstract" content="<?php echo $citationAbstract ?>">
	<meta name="citation_publication_date" content="<?php echo $citationPublicationDate ?>">
	<meta name="citation_journal_title" content="<?php echo $citationJournalTitle ?>">
	<meta name="citation_fulltext_html_url" content="<?php echo $citationFulltextHtmlUrl ?>">
	<meta name="citation_keywords" content="<?php echo $citationKeywords; ?>">
<?php if($citationAuthors) :
foreach($citationAuthors as $author ):  
	// Adjust "display_name" if necessary 
	?>
	<meta name="citation_author" content="<?php echo $author->display_name; ?>">	
<?php endforeach;
endif; ?>
<?php if($doiValid): ?>
	<meta name="citation_doi" content="<?php echo $doi; ?>">
	<?php if($intRechtDokPDFurl): ?>	
	<meta name="citation_pdf_url" content="<?php echo $intRechtDokPDFurl; ?>">
	<?php endif; 
endif; ?>

<!-- Meta Data for Reference Managers: Dublin Core tags -->
	<meta name="DC.type" content="blogPost">
	<meta name="DC.title" content="<?php echo $citationTitle ?>">
	<meta name="DC.abstract" content="<?php echo $citationAbstract ?>">
	<meta name="DC.date" content="<?php echo $citationPublicationDate ?>">
	<meta name="DC.source" content="<?php echo $citationJournalTitle ?>">
	<meta name="DC.source" content="<?php echo $citationFulltextHtmlUrl ?>">
	<meta name="DC.subject" content="<?php echo $citationKeywords; ?>">
<?php if($citationAuthors) :
foreach($citationAuthors as $author ):  
	// Adjust "display_name" if necessary 
	?>
	<meta name="DC.creator" content="<?php echo $author->display_name; ?>">	
<?php endforeach;
endif; ?>
<?php if($doiValid): ?>
	<meta name="DC.identifier" content="https://doi.org/<?php echo $doi; ?>">
	<?php if($intRechtDokPDFurl): ?>
	<meta name="DC.identifier" content="<?php echo $intRechtDokPDFurl; ?>">
	<?php endif;
endif;
	
endif;
}


GitHub Events

Total
  • Push event: 1
Last Year
  • Push event: 1