noteOn Mastodon

Watching Die Hard and working on my website. (I usually watch it around Christmas, but didn’t find the time.)

On Mastodon

Exclude Status Posts From RSS Feed in WordPress

I added a notes feature to my blog using WordPress’ status post format.

At some point I might create a separate RSS feed for those posts, but for now I wanted to exclude them from the general RSS feed, to keep it somewhat clean, containing only proper blog posts.

This is how I implemented it:

function my_theme_exclude_status_posts_from_feed( $wp_query ) {
	if ( $wp_query->is_feed ) {
		$status_posts = get_posts( [
			'posts_per_page' => -1,
			'tax_query' => [
				[
					'taxonomy' => 'post_format',
					'terms' => [ 'post-format-status' ],
					'field' => 'slug',
					'operator' => 'IN',
				]
			],
			'fields' => 'ids'
		] );

		$wp_query->set( 'post__not_in', $status_posts );
	}

	return $wp_query;
}

add_filter( 'pre_get_posts', 'my_theme_exclude_status_posts_from_feed' );

Please let me know, if you know of a better/cleaner way to achieve this.


Update: After some input from Mark, I rewrote it, with one query less:

function my_theme_exclude_status_posts_from_feed( $wp_query ) {
	if ( $wp_query->is_feed ) {

		$filter = [
			'taxonomy' => 'post_format',
			'terms' => [ 'post-format-status' ],
			'field' => 'slug',
			'operator' => 'NOT IN',
		];

		$tax_query = $wp_query->get( 'tax_query' );

		if ( is_array( $tax_query ) ) {
			$tax_query[] = $filter;
		}
		else {
			$tax_query = [ $filter ];
		}
		
		$wp_query->set( 'tax_query', $tax_query );
	}

	return $wp_query;
}

add_filter( 'pre_get_posts', 'my_theme_exclude_status_posts_from_feed' );
On Mastodon

Automatically Share WordPress Posts on Mastodon

Since Mastodon is really taking off (this time around), I was thinking about how to use it and integrate it into my general publishing workflow. (Not that I am posting much, but still.)

I have always been a fan of posting to my blog first, then to social media second.

A couple of days ago I activated post formats, more precisely the “status” format, to publish short notes, which do not warrant a proper blog post.

I also wanted to share those notes on Mastodon automatically. When looking into how to achieve that, I found the Share on Mastodon plugin. It is pretty straight forward to configure and it just works.

Jan, the developer, has added some well placed filters, which you can use to define exactly what is being shared. Have a look at the documentation with some examples on Jan’s website.

I made some adjustments using the share_on_mastodon_status filter, so that the post on Mastodon contains different things depending on the post format:

add_filter( 'share_on_mastodon_status', function( $status, $post ) {

    // Share only the post content if it is a status post
    if ( has_post_format( 'status', $post ) ) {
        $status = wp_strip_all_tags( $post->post_content );
    }
    // Share title + tags + url, if it is a regular post
    else {
        $status = wp_strip_all_tags( get_the_title( $post->ID ) );
        $tags = get_the_tags( $post->ID );
        if ( $tags ) {
            $temp = '';
            foreach ( $tags as $tag ) {
                $temp .= '#' . preg_replace( '/\s/', '', $tag->name ) . ' ';
            }
            $status .= "\n\n" . trim( $temp );
	}
        $status .= . "\n\n🔗 " . get_the_permalink( $post->ID );
    }

    return $status;

}, 10, 2 );

Let’s connect on Mastodon!

noteOn Mastodon

✨ Happy New Year, everyone!

noteOn Mastodon

Testing, testing, 1, 2, 3. This status update/note should be posted automatically from my #WordPress blog to Mastodon.

note

Back on the Keto train, after a carbohydrate-laden Christmas. Feeling pretty energized this morning.

note

Watching Devs. 7/10 so far, but I still have one episode left, so the final verdict is still out.

note

Is this thing on?

Experimenting with post formats again.

These have never really taken off, I guess? At least I do not see them used very often. Not even sure the newer default themes support them anymore? (I have to look that up!)

Anyway: This is a status post.

For now I have chosen not to include these posts in the feed or the xml sitemap. I might add a separate feed for these status updates and maybe even automatically posts them to Mastodon.

V 20

Whenever I work on this here website, I consider deleting a bunch of old posts. Then I remember how much I hate dead links. And although, imho, it is very likely that none of these old posts are linked anywhere or are in anybody’s bookmarks, the thought of returning a 404 is still uncomfortable.

On the other hand it is pretty informative for myself to go through those old posts, reminiscing. «Ah, the good old days!» But I digress.


With V 20 the minimalisation of this theme continues.

I didn’t plan to work on my website. I just started on Saturday afternoon with an idea, and finished, well… just now.

The idea was to have an “expanding about section”, that you can now see on the homepage. You are able to click on what ever interests you about me, and it will expand, give you some more information and show links for even further reading.

The inspiration for it probably came from Espen Brunborg, who’s talk I saw at beyond tellerand in Berlin a couple of weeks ago. He has this fun little dynamic element on his website, which I found to be very delightful. You can click through the history of his career by clicking the “Before that” link. (Keep clicking, it is funny!)

Anyway. Also – for the first time in a long time – I re-added some color to the site. At least on the homepage. (So much for minimalism!)

Final thought: I wish I had written a post like this everytime I updated my website/theme to a new version. And I would especially love to have a screenshot that shows what the site looked like before I made the update. Oh well, better start that tradition now.

V 19 – the e-bike is still awesome!

WordCamp Europe 2022

Sadly I won’t be attending WordCamp Europe in Porto this year. It just didn’t work out shedule-wise. It is especially sad, because I attended all installments of WordCamp Europe so far – first as attendee, then volunteer, then organizer.

Read more