Dublin Library

The Publishing project

Axios toolkit for WordPress API: Working with custom post types

The last two articles on using Axios with the WordPress REST API has worked with standard items in the WordPress world like post and pages. WordPress also gives you the option of creating your own content types with Custom Post Typeshttps://wordpress.org/support/article/post-types/ CPTs We create custom post types in PHP, either in a theme's functions.php or in a plugin. When working with the REST API, the important configuration is showinrest. Specifying this attribute with a value of true will make the custom post type available in the WordPress API. The CPT definition for an essay CPT looks like this: php array...

Continue reading →

Axios toolkit for WordPress REST API

As I'm learning the deep workings of the WordPress REST APIhttps://developer.wordpress.org/rest-api/ I'm also learning how to use Axioshttps://github.com/axios/axios as a replacement for Fetch. While I discovered that this will not work with Nuxt and the WordPress REST API, it's still a good starting point if you want to work with vanilla JS and templating engines. I am still researching how to make it work in Nuxt.js. Another thing that's important to note. Other than getJWT all other functions require authentication and I've chosen to use JSON Web Tokens JWThttps://jwt.io/introduction to authenticate the requests. The WordPress site uses the JWT Authentication...

Continue reading →

New research into block development

While researching block-based themes I found more information about blocks themselves and how to write them in a way you can submit them for inclusion in the WordPress directory. Most, if not all our blocks, will not be dynamic so we won't cover them in this post, just mention them in case that's what you're looking for. See creating dynamic blockshttps://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/creating-dynamic-blocks/ for more information Creating blocks with external metadata The block type metadatahttps://developer.wordpress.org/block-editor/developers/block-api/block-metadata/ provides an external means to declare our block API that will also be necessary if you decide to submit it to the block directoryhttps://wordpress.org/support/article/block-directory/. The metadata is...

Continue reading →

Gutenberg Full Site Editing and Block-Based Themes

Note Right now block-based themes and full site editing are still work in progress. I write about it because, sooner rather than later, themes will take advantage of full site editing and they will become a new tool in the arsenal for WordPress developers. These features are not part of Core WordPress, they require the latest Gutenberg plugin not the version that is bundled with WordPress, and the APIs discussed in this post may change before they are merged into core and become official parts of WordPress. An experimental feature available in recent versions of Gutenberg is the ability to...

Continue reading →

:is() CSS pseudo-class

There are times when we want the same element across the page to do the same. The following block styles the h2 elements inside the header, footer and main elements. css header h2, main h2, footer h2 { color: red; } It works but it's error-prone, repetitive and may cause all rules to be ignored if there is a mistake. Published in Selectors Level 4https://drafts.csswg.org/selectors-4/matches-pseudo, the :is pseudo-classhttps://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classestakes a selector list and selects any element that matches any of the selectors in that list. Using :is e can write the previous example like this css :isheader, main, footer h2 {...

Continue reading →

Revisiting Gutenberg blocks (part 3): other thoughts about Gutenberg

This post about Gutenberg is a mix of different thoughts, ideas and code snippets I've worked on while researching how to build blocks for a project I'm working on. Making Custom Post Types work in Gutenberg I've created several custom post types that worked in the classic editor. When I brought them to my Gutenberg playground they would not work or they would not work as I expected them to. It took me a while to realize that you must be really picky on how you configure the Custom Post Type CPT to work as Gutenberg is far less forgiving...

Continue reading →

Revisiting Gutenberg blocks part 2: More ways to customize blocks

The previous post Revisiting Gutenberg blocks part 1: Building and Styling the blockshttps://publishing-project.rivendellweb.net/revisiting-gutenberg-blocks-part-1-building-and-styling-the-blocks/ discussed how to build a block and reviewed both old and new techniques for creating Gutenberg blocks. This post will revisit related areas of block development in more detail. Block variations Some times it may be easier to create additional styles for an existing core element than create your own. Gutenberg calls this block variations. Authors can also choose whether they want to incorporate core blocks. It is highly likely that you will need to customize the block styles to match the core blocks with the theme...

Continue reading →

Revisiting Gutenberg blocks part 1: Building and Styling the blocks

My dislike of Gutenberg has softened since it was first introduced, mostly because they provided ways to keep the classic editor and they've guaranteed support for it through 2022. I've written about building Gutenberg blocks: Building Gutenberg Blocks Part 1https://publishing-project.rivendellweb.net/building-gutenberg-blocks-part-1/, part 2https://publishing-project.rivendellweb.net/building-gutenberg-blocks-part-2/, part 3https://publishing-project.rivendellweb.net/building-gutenberg-blocks-part-3/ and part4https://publishing-project.rivendellweb.net/building-gutenberg-blocks-part-4/, and another series on using Gutenberg as a design system: Gutenberg as a design system part 1https://publishing-project.rivendellweb.net/gutenberg-as-a-design-system-part-1/, part 2https://publishing-project.rivendellweb.net/gutenberg-as-a-design-system-part-2/, and part 3https://publishing-project.rivendellweb.net/gutenberg-as-design-systems-part-3/ but I want to revisit block design both in light of new developments in Gutenberg and as a way to build more complex blocks using block patterns and, possibly, full-page designs. Build...

Continue reading →

Building a performance test suite

Ever so often you see questions in Quora about Bravehttps://brave.com/, a Chromium-based browser that claims to be faster than stock Chromium and other derivative browsers like Edge, or Opera on Desktop. The last time I saw the performance testing results and methodology was when they first released version 1.0, documented in Brave 1.0 Performance: Methodology and Resultshttps://brave.com/brave-one-dot-zero-performance-methodology-and-results/ with the code used to do the analysis available on Githubhttps://github.com/brave-experiments/browser-comparison-toolkit but I haven't seen more recent data. The tests were done in older versions of the browsers tested and the Brave Browser Comparison Kithttps://github.com/brave-experiments/browser-comparison-toolkit hasn't been updated for newer versions not that...

Continue reading →

Custom Loops in WordPress

When researching how to use Gutenberg Ramp to partially allow Gutenberg on a WordPress site, I decided that I wanted to use a custom post type for the test so I wouldn't screw up the existing content for my blog. There is a problem with this idea. Custom post types don't appear in the default loop of a WordPress type so they wouldn't appear along with regular posts on the blog homepage. Most times, this is what we want. We want to use the custom post types on their own specialized loops. However, in this case, it is not what...

Continue reading →