WordPress: how to add a default title to your posts

This came up on the Fediverse: @[email protected] wanted to automatically add titles to the posts on his microblog.

This automation would have to be compatible with all the editors, including the mobile app.

GitHub GraphQL API: search for more than 1,000 Pull Requests

GitHub’s API is really handy when you want to get stats about one of your repositories. Its GraphQL API in particular is really powerful. I’ve shown how it could be used to fetch project information in my GitHub Actions tutorial.

While working on another project, I ran into a limitation that had me scratch my head for quite a bit. I wanted to share my workaround for anyone who may run into this problem in the future.

Code Reviews: credit your reviewers

A few months ago, I published The Power of a Conversational Code Review Culture. I talked about the importance of being generous with your code examples. Using GitHub’s built-in suggestions or posting diffs with the changes you have in mind go a long way towards helping the Pull Request’s author. It makes it easier for them to understand your suggestion, and include it in their code.

If you’re the reviewer and you already do this, kudos to you! Today I’d like to focus on the point of view of the Pull Request author.

How to add a Mastodon icon to your WordPress site

Following yesterday’s post, I’d like to do a bit of a follow-up. Sometimes you “just” want to add a Mastodon icon to your site, linking to your Mastodon profile:

I have one just like that on my home page, alongside my other Social Media links.

In this post, I’ll cover 3 different ways to add such an icon to your site.

 GitHub Actions: build your own JavaScript action — part 3

Let’s keep working on our GitHub Action! In the first parts of our series, we’ve discovered how to automatically add labels to an issue. Let’s explore some of the other things we can do with the Octokit client.

This post is part of the GitHub Actions: build your own JavaScript action series.

If you’re not following this blog yet, sign up here to get an email as soon as part 4 comes out:

GitHub Actions: build your own JavaScript action — part 2

In our last post, we built a JavaScript GitHub Action. That automation automatically adds an “Issue Triaged” label to all newly opened issues.

That’s great, but not necessarily very useful. In this second post, let’s look at an example of what we could do to make this a bit more useful!

GitHub Actions: build your own JavaScript action — part 1

If you work on GitHub, you’ll know GitHub Actions are powerful; they’re a great way to automate some of the tasks you regularly do in your repository.

GitHub introduced a marketplace where you can find actions for just about everything. This is a great way to get started with actions, see how useful they can be for your own projects.

In this series of posts, I’d like to go a bit further. We’ll be creating our own action to fit our exact needs. We’ll develop it within our existing repository, using JavaScript and GitHub’s own Actions Toolkit.

Jetpack: Add Related Posts to your RSS feed

I got an interesting question in the Jetpack support forums today. Levy wanted to display Related Posts in their RSS feed.

Jetpack displays Related Posts at the bottom of single posts by default, but like with other modules, you can customize Related Posts. In this post, we’ll use the the_content filter and the raw Jetpack Related Posts class to build our own unordered list of Related Posts, and add it to the bottom of the post content in RSS feeds.

Quick note before we start:

  • You’ll want to add that code to a functionality plugin like this one.
  • Nothing will happen if you’re not using Jetpack and its Related Posts module.
/**
 * Add Jetpack Related Posts to RSS feed.
 *
 * @see https://wordpress.org/support/topic/2927523
 *
 * @param string $content Post content.
 */
function jeherve_related_posts_feed( $content ) {
    // Return early if we're not in the RSS feed.
    if ( ! is_feed() ) {
        return $content;
    }

    // If Jetpack and Related Posts are active, let's get started.
    if ( class_exists( 'Jetpack_RelatedPosts' ) && method_exists( 'Jetpack_RelatedPosts', 'init_raw' ) ) {
        $related = Jetpack_RelatedPosts::init_raw()
            ->set_query_name( 'jetpackme-shortcode' ) // Optional, name can be anything.
            ->get_for_post_id(
                get_the_ID(),
                array( 'size' => 3 )
            );

        if ( $related ) {
            $related_list = '';

            foreach ( $related as $result ) {
                // Get the related post IDs.
                $related_post_id = get_post( $result['id'] );

                /**
                 * From there you can do just about anything, using the post IDs.
                 *
                 * In this example, we'll build an unordered list.
                 */
                $related_list .= sprintf(
                    '<li><a title="%1$s" href="%2$s">%3$s</a></li>',
                    esc_attr( get_the_title( $related_post_id ) ),
                    get_permalink( $related_post_id ),
                    get_the_title( $related_post_id )
                );
            }

            /**
             * Let's wrap all those related posts in ul tags, and add that list to the end of our post content.
             *
             * We will also add a headline, but only if it was set to be displayed in your Jetpack Related Posts settings.
             */
            $related_options = Jetpack_Options::get_option( 'relatedposts' );
            if ( $related_options['show_headline'] ) {
                $headline = sprintf(
                    '<h3 class="jp-relatedposts-headline"><em>%s</em></h3>',
                    esc_html__( 'Related', 'jetpack' )
                );
            } else {
                $headline = '';
            }

            return sprintf(
                '%1$s%2$s<ul class="jp-relatedposts">%3$s</ul>',
                $content,
                apply_filters( 'jetpack_relatedposts_filter_headline', $headline ),
                $related_list
            );
        }

        return $content;
    }

    // Last fallback, just in case Jetpack and Related Posts aren't there anymore.
    return $content;
}
add_filter( 'the_content', 'jeherve_related_posts_feed' );

How to create Tiny Planets (photo spheres) in Android 5.0+ (Lollipop)

When Android 4.2 was released, one of my favorite features was the new Camera app and its Photo Sphere option. It allowed you to take 360-degree panorama pictures, and you could then use the photo editor to create a “tiny planet” from this panorama. I actually published a few here on my blog:

When Android 5.0 (Lollipop) was released, it appeared that the option was gone from the editor. You could still create Photo spheres, but I couldn’t find a way to create the Tiny Planets. Lucky for me, I finally found the option back!

If, like me, you can’t locate the option anymore and would love to create your own little worlds again, without having to use a third-party app, follow the steps below.

A gold mine for your functions.php file

If you have played with WordPress themes in the past, you know that there are many tutorials sites all around the web gathering and proposing small functions to insert into your theme to make it better/harder/faster/stronger…

Here is the new kid on the block: WPfunction.me

Careful though: it is sometimes better to create a small plugin than to paste yet another function in your theme!

WordPress Functions.php snippets
WPFunction.Me lets you quickly build all the functionality you need for your next WordPress project!