The Method to Change the Slugs for IndieBlocks Notes and Likes

heart and zero neon light signage

Plugin Introduction

IndieBlocks is a beginner-friendly IndieWeb plugin that easily enables IndieWeb features on your WordPress site, effectively giving your site basic social media functionalities.

This plugin provides several “blocks” (a basic editing unit in the WordPress Gutenberg editor), including:

  • Bookmarks
  • Likes
  • Replies
  • Reposts

You can input URLs into these blocks and get microformatted HTML outputs.

Combined with a theme compatible with microformats and clients that support microformats, it can determine the type of post (whether it’s a regular post, reply, repost, etc.).

Clearly, these are features provided by microblogging services. If there’s a need to distinguish this kind of microblogging content from the site’s existing (serious) long-form content, this plugin provides custom post types for microblogging content: ‘notes’ and ‘likes’ – the focus of this article.

These microformats combined with the Webmention protocol can enable rich cross-site dialogues. IndieBlocks comes with its own Webmention implementation, but it can also use standalone plugins.

The Method

The default slug for the ‘note’ post type is ‘notes’, and ‘like’ is ‘likes’. For example, the URL for a note on my site looks like this:

The ‘microblog’ in this URL is the slug for this note type. Some readers might notice: ‘microblog’ and ‘notes’ – why are the slugs different? This is because I have modified the default slug.

Implementation Code

The official documentation provides a way to modify the default slug. Add this code to `functions.php`:

add_action( 'register_post_type_args', function( $args, $post_type ) {
  if ( 'indieblocks_note' === $post_type ){
    $args['rewrite']['slug'] = 'microblog'; // new slug

  return $args;
}, 99, 2 );

Here, ‘indieblocks_note’ is the type name for the ‘note’ post. This code changes the slug of the note to ‘microblog’.

(If you access the WordPress site database, you will see the ‘post_type’ column in the ‘wp_posts’ table (or ‘wp_ site number _posts’, such as ‘wp_10_posts’) presents names like ‘post’, ‘attachment’, ‘revision’, etc. These are the names of their respective ‘post types’. For more details about post types, please read the official documentation.)

Similarly, if you want to change the default slug ‘likes’ for ‘like’ to ‘stars’, do this:

add_action( 'register_post_type_args', function( $args, $post_type ) {
  if ( 'indieblocks_like' === $post_type ){
    $args['rewrite']['slug'] = 'stars'; // new slug

  return $args;
}, 99, 2 );

‘indieblocks_like’ is the post type name.

It’s quite poetic to liken giving a like or thumbs up to sprinkling little stars.

Modification Method

The above modification to the `functions.php` code is recommended to be implemented via creating a new child theme. This way, all modifications to the `functions.php` code will not be overridden when the theme is updated.

You can also insert the above code using the Code Snippets plugin. The advantage of doing this is that it saves the hassle of setting up a new child theme and allows you to complete all the work on the front end (as opposed to directly modifying `functions.php` on the back end).

Refresh Cache

What’s not mentioned in the plugin’s official documentation is the possibility that old links will not update after the code is used. Some readers’ sites may already have a stock of notes or likes. After the above modification, the URLs of the existing content do not change along with it. In this case, consider:

  1. Go to ‘Settings’ > ‘Permalinks’ in the WordPress Admin panel, and then click the ‘Save Changes’ button to refresh the permalink structure.
  2. If your site uses a caching plugin, clear the cache.

Then, you will find that all URLs are updated.

In my case, there was no caching plugin installed on the site, so the problem was solved in the first step. However, if a caching plugin is installed, the possibility is conceivable.

Discover more from Sang-nguok

Subscribe now to keep reading and get access to the full archive.

Continue reading