Add Microdata For “Person” To WP Family Tree Plugin

This shows you how to add microdata to WP Family Tree (“WP Family Tree” WordPress Plugin by Arvind Shah). I add microdata for the ‘Person’ item type. Then I add the ‘Person’ properties ( itemprop ) of name, birth date, death date, parent, children, sibling, and image. These changes will take effect on single family member pages, and on the family members list page. These changes will not affect the dynamic tree page, though (which is unnecessary, anyway).

Microdata is HTML5-friendly, and is also the preferred markup of Google for rich snippets. Here I use Schema.org specifications because it allows for more ‘Person’ properties than the old data-vocabulary. For example, the old data-vocabulary does not include death date nor sibling properties.

Let’s begin.

FILE TO EDIT: wp-content/plugins/wp-family-tree/class.node.php

Change 1 – Add microdata itemtype ‘Person’

Find this code, which should be about line 53:

$html = '<table border="0" width="100%">';

Change that line to this:


$html = '<table border="0" width="100%" itemscope itemtype="http://schema.org/Person">';

Change 2 – Add Itemprop Name

Find this code, which should be about line 57:

$html .= $this->name.'</a></b></td>';

Change that line to this:

$html .= '<span itemprop="name">'.$this->name.'</span></a></b></td>';

Change 3 – Add Itemprop Image

Find this code, which should be about line 47:

$fm->thumbhtml = get_the_post_thumbnail($post_detail->ID, 'thumbnail');

Change that line to this:

$fm->thumbhtml = get_the_post_thumbnail($post_detail->ID, 'thumbnail',array('itemprop' => 'image'));

Change 4 – Add Itemprop For Birth Date

This adds the itemprop=”birthDate” microdata to the Person’s date of birth.

Find this code, which should be about line 79:

$html .= '<td style="vertical-align:bottom">Born: '.$this->born.'</td>';

Change that line to this:

$html .= '<td style="vertical-align:bottom">Born: <span itemprop="birthDate">'.$this->born.' </span></td>';

Change 5 – Add Itemprop For Death Date

This adds the itemprop=”deathDate” microdata to the Person’s date of death.

Find this code, which should be about line 81:

$html .= '<td style="vertical-align:bottom">Died: '.	$this->died.'</td>';

Change that line to this:

$html .= '<td style="vertical-align:bottom">Died: <span itemprop="deathDate">'.	$this->died.' </span></td>';

Change 6 – Add Itemprop Parent, For Father

This adds the itemprop=”parent” microdata to the Person’s father.

Find this code, which should be about line 88:

$html .= '<a href="'.$this->url_father.'">'.$this->name_father.'</a>';

Change that line to this:

$html .= '<a href="'.$this->url_father.'" itemprop="parent">'.$this->name_father.'</a> ';

Change 7 – Add Itemprop Parent, For Mother

This adds the itemprop=”parent” microdata to the Person’s mother.

Find this code, which should be about line 95:

$html .= '<a href="'.$this->url_mother.'">'.$this->name_mother.'</a>';

Change that line to this:

$html .= '<a href="'.$this->url_mother.'" itemprop="parent">'.$this->name_mother.'</a> ';

Change 8 – Add Itemprop Children

This adds the itemprop=”children” microdata to the Person’s children, if any are listed.

Find this code, which should be about line 109:

$html .= '<a href="'.$the_family[$child]->url.'">'.$the_family[$child]->name.'</a>';

Change that line to this:

$html .= '<a href="'.$the_family[$child]->url.'" itemprop="children">'.$the_family[$child]->name.'</a> ';

Change 9 – Add Itemprop Siblings

This adds the itemprop=”sibling” microdata to each of the Person’s siblings, if any are listed.

Find this code, which should be about line 124:

$html .= '<a href="'.$the_family[$sibling]->url.'">'.$the_family[$sibling]->name.'</a> ';

Change that line to this:

$html .= '<a href="'.$the_family[$sibling]->url.'" itemprop="sibling">'.$the_family[$sibling]->name.'</a>';
NOTE: This code modifies the plugin core. If you do this, keep a change log of your changes. You’ll have to make these changes again after upgrading the WP Family Tree plugin to a new version. As always, modifications made to the plugin core will be overridden when you upgrade the plugin. The extra work is worth it to me, for a plugin that does what I want it to do. I keep a simple changelog. Re-doing all my customizations after an upgrade takes me about 2 minutes.

See more: , , ,

We've 2 Responses

  1. March 15th, 2019 at 12:21 am

    Do you know how to update teh wpfamilytree plugin? I’ve tried hacking at it to fix/add a spouse field. Arvind half did it.
    If Google is right, he passed away in 2010.
    I’m looking for someone to help me fix a bug.

    john t-johnston
    • March 25th, 2019 at 3:25 pm

      RE: “If Google is right, he passed away in 2010.”
      I did not know this. Very sad. I forked his WP Family Tree plugin and modified it many years ago. Here is my fork on GitHub. I have not looked at it in several years. What is the bug?

      Isabel

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]