How to Easily add Family Tree JS 2 in WordPress
Creating a family tree on your WordPress website might sound like a complex task, but with the right tools, it’s surprisingly easy. We’ll walk you through a simple way to create a beautiful, interactive family tree using Family Tree JS 2 and a lightweight WordPress plugin.
Let’s get started!
🧩 Step 1: Install the "Insert Headers and Footers" Plugin
Log in to your WordPress dashboard.
Navigate to Plugins > Add Plugin.
In the search bar, type Insert Headers and Footers.
Click Install Now, then Activate.
This plugin allows you to easily add custom code to your site’s <head>
and <body>
sections—perfect for loading external scripts.
⚙️ Step 2: Add FamilyTreeJS Code to Your Site
Once the plugin is activated:
Go to Settings > WP Headers and Footers in your dashboard.
In the Scripts in Header section, paste the following:
<script src="https://cdn.balkan.app/familytree2.js"></script>
<div id="tree"></div>
<style>
html, body{
width: 100%;
height: 100%;
padding: 0;
margin:0;
overflow: hidden;
font-family: Helvetica;
}
#tree{
width:100%;
height:100%;
}
</style>
This loads the Family Tree JS 2 library, adds a <div>
element where your tree will appear and the CSS.
- In the Scripts in Body section, add this script:
<script>
let familyTree = new FamilyTree2(document.getElementById('tree'));
familyTree.addFamilyMembers([
{
id: 1,
fatherId: 2,
motherId: 3,
spouseIds: [4],
siblingIds: [5, 6],
childIds: [7],
name: 'Me'
},
{id: 2, name: 'Father'},
{id: 3, name: 'Mother'},
{id: 4, childIds: [7], name: 'Spouse'},
{id: 5, name: 'Sibling 1'},
{id: 6, name: 'Sibling 2'},
{id: 7, name: 'Child'}
]).draw(1);
</script>
This script initializes the tree and adds seven example family members.
💾 Step 3: Save and View Your Family Tree
Click Save at the bottom of the settings page. Now, when you visit your site, you’ll see your interactive family tree!
✅ Final Thoughts
With just a few steps, you can enhance your WordPress site with a fully interactive family tree. It’s ideal for personal blogs, genealogy projects, or even family reunion websites.
Explore more options in the FamilyTree JS 2 documentation.
If you have questions or want to see how to customize it further—drop them in the comments below!