That shift from using a tool for a task to reshaping it for a future one is maybe the thing I love most about my efforts at coding (given my lesser skills with real hand tools).

Quite often I find myself making small tweaks to things I know are in my projects; but will anyone else ever know?

For a new WordPress project setting up some template sites for Portfolios, in the interest of speed, I’ve recommended using the JetPack feature that creates custom post types for portfolio content (and some of the themes built to use them).

A “custom post type” means that when people add content, it looks and acts like a normal blog post, but the content is separate, so the blog part can be used more for reflection, news, etc. The Portfolio content also gets its own category and tag taxonomies.

The itch under my skin is the terminology used in the custom post-type. Items added to a portfolio are called “Projects” which might make sense if you are building a portfolio of your web clients, crafts, etc, but seems a bit off to me for a learning portfolio. And for the school I am working with they use “Artifacts”.

So I dug into seeing how the Jetpack plugin works. And that is significant, as I can see all of their code. And having coded my own custom post types for projects like the DS106 Assignment Bank theme I have a fair understanding of the register_post_type functions.

The trickier part was finding a way to modify this in a child theme. With a bit of poking around I found a tip on a blog showing that there was a WordPress filter hook built to do this register_post_type_args, where I was able to change all the labels used for “Projects” in the dashboard to “Artifacts”

I just modified the labels part of the array I saw in the Jetpack code used to create a custom post type.

But there is more as there are labels used for the two custom taxonomies created for the categories and tags. My hunch, which was wrong, was that there would be a wordpress hook for modifying a custom taxonomy. I did find what I was looking for in StackExchange (where I find maybe 80% of my code help)- use a wordpress to get all the info about a custom taxonomy, replace parts, and spit it back out, more or less child functioning it.

And thus I have minor success, I’ve changed all references (I hope) in the themes I am making so that the things inside a portfolio are called “Artifacts” rather than “Projects”.

But while I was in the Jetpack code, I noticed use of a function to change the messages that appear when a custom post type is modified (or even in some of my SPLOTs like TRU Collector, where I renamed “Posts” to be “Collectibles”). WordPress always responds with “post updated” or “post published” when I no longer or never call them posts.

I found the WordPress hook post_updated_messages that is used but no real explanation I could decipher. So I figured out from the Jetpack code, and a post from What About WordPress that you simply return an array with reworded versions of the 10 messages the WordPress admin uses.

I’m folding these into the SPLOT family themes soon.

Tiny stuff.

The last little bit was following the Jetpack plugin code where it changed the heading for Column listing of content in the dashboard from “Title” to “Project”, so I follow suit and change it once more to “Artifact”.

Because I can.

All of the add_filter() bits I wrote have a priority value of 11 so it happens after Jetpack does its stuff (using the default 10 value).

If everything works well, you likely never notice it.

But I know it’s there, and in the process, I figured out tings I can use in future projects. Or artifacts. Wait, don’t substitute that!)


Featured Image:

If this kind of stuff has value, please support me by tossing a one time PayPal kibble or monthly on Patreon
Become a patron at Patreon!
Profile Picture for CogDog The Blog
An early 90s builder of web stuff and blogging Alan Levine barks at CogDogBlog.com on web storytelling (#ds106 #4life), photography, bending WordPress, and serendipity in the infinite internet river. He thinks it's weird to write about himself in the third person. And he is 100% into the Fediverse (or tells himself so) Tooting as @cogdog@cosocial.ca

Comments

  1. Serious question – what’s the merits of baking these changes into a theme versus doing a custom language pack? I guess if it’s baked into a theme it will survive Jetpack upgrades, which a local translation might not? The flipside is a language translation would let this change be used with any theme, which if it’s institutional specific terminology, might be attractive as well?

    1. Serious answer, I’m not quite sure. I’ve not done much to anything with language packs, and what impact does this have on changing the language as needed in non English-landia. A few changes (url slugs) are outside of that scope. But something to think about and look into

      1. I had a quick poke about and since the Jetpack plugin is top quality it comes with language files for most languages. They’re part of the plugin structure though, so still a question about whether they would survive an upgrade of Jetpack (especially if you were just changing the file for your chosen language). I don’t know if it’s possible to put translation files for plugins where ever the core WP translation files are (or bake them in instead). It’s got me thinking though that it could be quite useful to have a default blog site language which was your language plus institution e.g. English(UK) – Edinburgh. It could be baked into the default template site on a WP multi-site install then I’ve got all my institution specific language right there from the start. Hmm….I started pondering this because we want to change some default labels to reference our local authentication system. One to keep pondering.

        1. Yes, this offers some potential, it looks like via https://wordpress.stackexchange.com/a/225220/14945 and confirmed here https://developer.wordpress.org/themes/functionality/localization/#using-localizations you can create a server side directory at /wp-content/languages for .pot files that do not have to come from plugins. Then you define that as the default language in the config.php for the site. It might also be available from the language choices at a user level. Just guessing.

Leave a Reply

Your email address will not be published. Required fields are marked *