The Publishing Project

Adding CPT and Taxonomies to an existing theme

In the last post, we covered the technical part of creating Custom Post Types (CPTs) and Taxonomies. This post will cover integrating the CPT into a theme. We will also discuss issues regarding using CPTs as a plugin and modifying an existing theme or child theme versus incorporating the code for the CPT into a theme. Choosing deployment strategies The most common way to deploy CPTs is to bundle the code in a plugin and deploy them independent of the theme you’re using. This means that you will have to customize whatever theme you choose by creating a child theme

WordPress Custom Post Type for Glossary Project

I’ve been playing with the idea of creating a technical glossary for referring to technical terms on my posts. After a lot of research I came back to a simple tool: WordPress custom post types (CPT). The idea is as follows: Create a custom post type plugin for glossary entries Create the post type Change the labels as appropriate Ensure that it will appear in the REST API and use Gutenberg if desired Create a corresponding taxonomy Change the labels as appropriate Ensure that it will appear in the REST API Explore how to incorporate the CPT and taxonomy into

Creating arrays from node lists

Using querySelectorAll to get one or more items and then process them as an array of items is not as straightforward as I initially thought it would be, at least in the browsers I use for testing Part of the problem is that querySelectorAll returns a node list and some of them will not work with node lists and will require the conversion to an array before we do anything. We’ll look at three ways to work with node lists as arrays. The last one works with node lists directly. The examples will each take all the paragraphs on a

When to use appendChild, insertAdjacentHTML or append

One thing that has always puzzled me is how to insert content into an existing document. In researching this I found two traditional alternatives and a newer API that may make things easier. Recently I was playing with JSON-LD and trying to append content that used the JSON data into the page. The code looked like this: const data = document.getElementById(“data”).text; const json = JSON.parse(data); const displayData = ` <h2>${}</h2> <h3>by ${}</h3> <p>${json.description}</p> `; The first idea was to use appendChild to append displayData to the document but it didn’t work. displayData expects a node as its parameter and displayData

JSON-LD on the web

JSON-LD is a set of extensions to JSON that allows for creating and exchanging linked data on the web. Perhaps the best-known use of JSON-LD outside semantic web users is using’s JSON-LD structured data for Google’s search engine. The following example gives the structured data snippet to accompany a recipe web page. The example is taken from Understand how structured data works. <html> <head> <title>Party Coffee Cake</title> <script type=”application/ld+json”> { “@context”: “”, “@type”: “Recipe”, “name”: “Party Coffee Cake”, “author”: { “@type”: “Person”, “name”: “Mary Stone” }, “datePublished”: “2018-03-10”, “description”: “This coffee cake is awesome and perfect for parties.”, “prepTime”: