Hidden in the Code

A quote about URLs from Tom Woodward

This is a collection of code that I often turn to when working with WordPress


Every time that I feel comfortable with my level of knowledge associated with WordPress, there is a problem that leads me to discover a particular attribute that I don’t know how I lived without. This time it is the code seemingly obfuscated beyond the WYSIWIG editor and the dashboard.

For some this code is about command line, while others it is about the bashing out the building blocks. My interest here is the everyday code, the little snippets that find there way in here or there while I work with WordPress, many of which have come from wandering through Chris Aldrich’s commonplace blog:

Webmentions

Webmentions are the building block for conversations across the web. However, with WordPress, they often get caught in moderation and/or flagged as spam by Akismet and other spam filter plugins. To prevent this, you can add this PHP snippet to your theme’s functions.php file:

function unspam_webmentions($approved, $commentdata) { return $commentdata['comment_type'] == 'webmention' ? 1 : $approved; } add_filter('pre_comment_approved', 'unspam_webmentions', '99', 2);

Alan Levine has documented the process of creating a child theme, which is useful when customising the code, while Gregor Morrill has developed code to approve webmentions from domains previously approved.

Microformats

Microformats is a data format built upon adopted standards and prior developments. There are a number of specifications, which can be manually added within the existing HTML. It provides the foundation for software to automatically process information. People like [David

Shanske](https://github.com/dshanske/twentysixteen-indieweb) and Matthias Pfefferle have developed plugins and themes to mark-up content in the backend. You can also use this site to check the microformats on your site, while for a more extensive introduction, listen to Tantek Çelik on the future of web apps.

Two microformats I have worked with are comments and rel=me.

Comment

Although the appropriate microformats are usually built into the Webmentions plugin. The plugin for theaded comments can be a bit more tempremental. [Chris Aldrich](http://boffosocko.com/2017/12/15/threaded-replies-with-webmentions-in-wordpress/] recommends manually adding the reply class and URL just to make sure:

 <a class="u-in-reply-to" href="http://www.example.com"></a>

I have come to do this out of habit for replies now.

Rel-me

Another microformat incorperated into many Indieweb sites is Rel-me. It is used to consolidate identity, as well as domain sign in.

<ul> <li><a href="https://twitter.com/aaronpk" rel="me">@aaronpk on Twitter</a></li> <li><a href="https://github.com/aaronpk" rel="me">Github</a></li> <li><a href="https://google.com/+aaronpk" rel="me">Google</a></li> <li><a href="mailto:me@example.com" rel="me">me@example.com</a></li></ul>

Chris Aldrich has taken rel-me to its extremes by creating a page in which he records all his accounts. I have also started my own. For more on rel-me, watch Ryan Barrett’s keynote at IndieWeb Summit 2017.

Page Bookmarks

I remember coming across in plugin in Edublogs that allowed you to add a table of contents. This reminded me of the functionality in Google Docs and one of the things I noticed in both was the presence of a hashtag at the end of the URL. (Interestingly, now every heading in Google Docs has a unique identifier automatically created.) In Docs, this is something that can be added using the Bookmark feature, I wondered if the same could be done in WordPress. I discovered that within the tags, you insert ‘name=”unique-name”‘:

<a name="unique-name">Target Text</a>

This can then be used to guide readers to a specific point in your text.

Custom URLs for Post Kinds

Using the Post Kinds plugin provides a list a unique urls associated with the kinds of posts on the site. Chris Aldrich provides some guides in how to use these to create custom urls to generate a specific post screen. This can then be used to create a bookmarklet:

 http://example.com/wp-admin/post-new.php?kind=bookmark&kindurl=@url

Dariusz Kuśnierek provides some other examples of custom URLs, which help in U deratamding the way urls work in general.

RSS Feeds

RSS provides a means of following a site without checking in all of the time. To access a feed to follow in WordPress, you simply add ‘/feed/’ to the end:

http://www.example.com/feed

As some feeds can contain a range of content, it is possible to hone down to particular categories by adding ‘?cat=[category id]’ to the end.

http://www.example.com/feed?cat=[category id]

This can be useful if you only want to follow a specific subject or area.

Taking this a step further, you can also produce an RSS based on Post Kinds. Although not all blogs use these, for those that do it can be a useful demarcation. Similar to categories, you add ‘?kind=type’ to the end of the feed.

http://www.example.com/feed/?kind=bookmark 

For more on RSS feeds, see this post from Chris Aldrich.

OPML

Where as RSS is used for a single feed, OPML allows a user to aggregate. I have written about them before. It is possible to store an OPML in WordPress. To access this you add the append ‘/wp-links-opml.php’ to the end.

http://www.example.com/wp-links-opml.php

In addition to this, Chris Aldrich has documented how to split a file into categories:

?link_cat=[category id]

I have yet to categorise my links, however Aldrich provides an extensive example.


So what about you? What little bits of code do you use? As always, comments welcome.


If you enjoy what you read here, feel free to sign up for my monthly newsletter to catch up on all things learning, edtech and storytelling.

Also on: