Over the last couple of months I’ve been learning to code, partly just for the sake of something to learn, but also partly for the sake of developing a child theme for my blog. In this post, I’ll talk a bit about how the child theme creation process is going, but to start off, what the heck is a child theme?

Every WordPress blog has a theme. Themes are layered on top of the WordPress core and influence the design of your site, both in terms of how it looks when other people are looking at it and how it looks to you in the editor. A child theme is layered on top of a parent theme to further influence how a site looks and behaves. The reason for creating a child theme rather than just tweaking the parent theme directly is that each time a new update of the parent theme is released, any modifications that an individual user had been made to the previous version of the parent theme are lost. Because a child theme sits on top of a parent theme, it keeps on doing its thing even if the parent underneath it has updated.

Another way of customizing WordPress sites is adding plugins (although most WordPress.com plans don’t let you do that). These add extra functionality. Since the child theme I’m building is just for me rather than being created for other people to be able to use, I’m actually focusing more on functionality than presentation, but it’s easier to do things all in one place in the child theme than to create a plugin as well.

My child theme

Today was the first time trying out the child theme on my actual site. Up until now, I’ve just been working on it using a test site that only runs on my computer. My child theme changes a few things behind the scenes, including incorporating some functionality that I’ll no longer need to use plugins for. It changes very little about the way my site looks, though, because I’m using the same code for that kind of thing as I had already been using as custom CSS (Cascading Style Sheets) code in my parent theme (which is Astra).

One thing I’ve added is making an author bio appear at the bottom of posts, but only on specific post categories and only on the site itself rather than in the RSS feed, which is what’s displayed in feed readers like the WordPress Reader. I’m not actually changing the content of the posts themselves, but tacking an extra bit of code on right when a post is being displayed. I felt rather pleased with myself when I got that working.

Speaking of the RSS feed, I have my Amazon author profile set up to display my blog feed, but there are certain categories of posts that I’d rather not have displayed there. To address this, I used my child theme to create a custom RSS feed in addition to the feed WP automatically creates for my site, and my custom feed filters out posts from specific categories.

I had things working with a feed reader I found that could display feeds created by a local site that wasn’t actually on the internet… or at least, it was working the last time I had tested it. Somehow, I managed to break it since then without realizing it. Anyway, when I uploaded the child theme to my live site, not only did the custom RSS feed not work, but it managed to break my regular feed as well. I’ve disabled the custom RSS feed until I can figure out how I managed to fuck it up, and I think I’ve unbroken the regular feed, but it’s a toss-up whether this post will appear in the WP Reader.

Work in progress: custom blocks

I’ve been using a plugin that was called Ultimate Add-Ons for Gutenberg that includes a number of different types of blocks above and beyond the standard block types available in WordPress (like a table of contents block I use on several of my site”s pages). The plugin-maker has recently totally overhauled the plugin and the overhauled version is a bit of a disaster, so I decided to try to use my child theme to create the block types I want to be able to use rather than having to use the plugin. I took a LinkedIn Learning course to learn how to create custom blocks, and now I’m in the process of trying to build a table of contents block.

If you think the block editor is a pain in the ass to use, blocks are even more of a pain in the ass to code. A lot of WordPress stuff is coded using the PHP language, but building Gutenberg blocks involves a different language (JavaScript), plus some other stuff on top of that (React and npm).

So far, I’ve got my basic custom block created and I can use use it in posts just like any other kind of block. Now I’m working on the hard part, which is getting it to generate a functioning table of contents on the fly using the headings in a post.

So that’s a bit of an update on what I’m working on. I know this is something the vast majority of people will have less-than-zero interest in doing for their own site, but I’m finding it kind of fun to tinker around with WordPress nuts and bolts.

Blogging toolbox: graphics of toolbox and wordpress logo

The blogging toolbox series has tips to support you in your blogging journey. It includes these posts:

Source link

Previous articleBuffalo Blue Mac & Cheese
Next articleZhejiang University School of Medicine Expands Care In China