Hello, my name is Alex Mansfield. I am primarily a freelance WordPress developer, but I occasionally work on other design and development projects.

Linux Command Line: Find Files with Matching String

I know this is documented in various places around the web, but I’m tired of hunting it down whenever I need it. Often when working with websites and code, I need to locate any files that contain a particular string. This command searches a folder recursively and prints out the filename of any files that contain the string:

find . | xargs grep 'example string' -sl
  • PublishedNovember 30, 2016
  • Posted InLinux

Displaying Custom Post Types in a Custom Taxonomy Archive

The project I was working on today required a custom post type that included a custom taxonomy. Setting this up on the back end was simple. However, when I went to the front end, all the posts in the custom post type were missing from the custom taxonomy archive. Since it took me way too long to figure out the source of this issue, I’m going to document it here.

It all comes down to this poorly named setting:

exclude_from_search

When registering a post type, this setting determines whether or not your custom post type will show up in your site’s search results. However, it also has the unexpected side effect of determining whether or not your custom post type will show up on taxonomy archive pages. If you want to include your custom post type in custom taxonomy archives, exclude_from_search must be set to false:

'exclude_from_search' => false,

Note: If the “public” setting is set to “true” then the “exclude_from_search” setting can simply be removed.

Special thanks to Pieter Goosen for mentioning this issue in this Stack Exchange thread.

This issue is also mentioned in the “exclude_from_search” section of the old WordPress Codex page for registering custom post types.

  • PublishedAugust 12, 2016
  • Posted InWordpress

Migrating WordPress Multisite to a Local Development Environment

This post is primarily a reminder to my future self. However, I don’t think I’m alone in this struggle. Migrating WordPress multisite can be quite a challenge, especially if you’re migrating from a live site to a local development environment. If you’re using http://localhost as your local development environment root with individual sites placed in subfolders like I was doing, your URL structure is most likely quite a bit different than the live site you’re trying to migrate.

Some day I may write a full tutorial on how to accomplish this, but for now I just want to highlight the missing piece that I didn’t find in any other tutorials (and that I spent a few days trying to find).

(more…)

WordPress Audio: Add a Download Button to mediaelement.js

So I got a call this morning asking how to download an audio file that WordPress was presenting with medialement.js. As you might have noticed, since WordPress started providing an audio player there hasn’t been an easy way to allow audio files to be downloaded as well as played. This has bothered me for a while, but this morning’s call gave me the incentive to look into it further.

My first thought was to use a custom field to store the audio file URL. Then I could display both a player and a download button based on the same URL. However, the site I was working on had years worth of audio, and I didn’t want to go through post by post and move the audio file URL out of the post editor and into a custom field. My next thought was to modify how WordPress loaded the media player and hopefully filter the output to add a download link. While this may be possible, I ended up deciding against digging into the filters in WordPress core and just used a few lines of jQuery. Here’s what did it:

// Add download links to default audio player.
$( document ).ready(function() {
	$('audio').each(function( index ) {

		var source = $(this).find('source').attr('src');

		if ( source != '' ) {
			$(this).after('<a href="' + source + '" class="audio-download" download>Download</a>');
		}

	});
});

Keep in mind you’ll need to load jQuery in order for this to run.

I just added a few lines of CSS to style the new download buttons:

a.audio-download {
	margin-top: 1em;
	background: #eee;
	padding: 0.5em 1.5em;
	border-radius: 5px;
	display: inline-block;
}

a.audio-download:hover {
	background: #ddd;
}

…and that’s it!

 

  • PublishedJanuary 29, 2015
  • Posted InHacks

Setting Up Ubuntu/Linux Mint for Web Development

Every so often I switch computers or reinstall my OS and end up searching around the web for the exact steps to get everything working again. Today, as I set up my OS again, I figured I might as well document the process. Since Linux Mint is based on Ubuntu, I think that these steps (at least most of them) should work for Ubuntu users as well. (more…)

  • PublishedMarch 4, 2014
  • Posted InLinux

Creating a Commercial WordPress Theme Review Site in One Week: Day 4

This is the fifth in a series of posts documenting the creation of Theme Friendly, a website dedicated to reviewing commercial WordPress themes.

On day four, I built the search page. This was easily the most difficult part of the entire process. Let’s start with the screenshot.

Day 4 Screenshot

friendly-day-4

If you read my post covering day 3 you might be thinking, “Hey! this looks almost like the review archive from the last post.” …and you would be right. I reused the template part I created for the review archive to display the search results. Adding the search form was a little more difficult though, and filtering the search results based on the input from the search form was even more difficult. Here’s how it worked… (more…)

  • PublishedJanuary 7, 2014
  • Posted InProjects

Creating a Commercial WordPress Theme Review Site in One Week: Day 3

This is the fourth in a series of posts documenting the creation of Theme Friendly.

On day three, I built the review archives page. I don’t think this page will be used directly, but on day four I incorporated it into the search results page, so it was still worth building.

Day 3 Screenshot

friendly-day-3

After all the hard work that went into building the single review page on day 2, this page was pretty short and sweet. It only had to display each theme’s title, quality score, thumbnail, and author. Most of the backend code was easily modified from the single review page code. I just had to add a new image size and some CSS to handle the new layout.

In the next post in this series, I’ll be detailing how I built the search functionality that makes it simple to find only themes that match your exact requirements. Sign up for the Theme Friendly newsletter to find out when it is published. Until then, Happy New Year!

  • PublishedDecember 31, 2013
  • Posted InProjects

Creating a Commercial WordPress Theme Review Site in One Week: Day 2

This is the third in a series of posts documenting the creation of Theme Friendly.

On day two, I set about building the individual theme review page. The goal was to provide a quick overview of the quality of a theme as well as it’s features. This was to be done by displaying the contents of all the custom meta boxes and custom taxonomies created on day one.

Day 2 Screenshot

friendly-day-2

(more…)

  • PublishedDecember 17, 2013
  • Posted InProjects

Creating a Commercial WordPress Theme Review Site in One Week: Day 0

This is the first in a series of posts documenting the creation of Theme Friendly.

A short history

I’ve been thinking about building a commercial WordPress theme directory for a number of years now. I even tried (and failed) to get one off the ground a few years ago. During that time, a number of other sites sprung up with similar goals and I gradually abandoned my project. However, the idea never left. I kept thinking about what could be done to ease the process of finding the perfect WordPress theme for any particular project. I decided to see if I could build a working solution in just one week.

(more…)

  • PublishedNovember 27, 2013
  • Posted InProjects

« Older Entries