Posts Categorized: Code

Managing Multiple SSH Keys for Git Push On WP Engine

If you ever find yourself in a situation where you need to manage multiple “Git Push” users, i.e. keys on the WP Engine platform, here’s a handy little trick to make things more manageable on your local system (Instructions for Mac based system, adjust as necessary.).

$ cd ~/.ssh/ – Find and navigate to your ssh directory ($ indicates prompt)
$vim config – open/edit your config file

(more…)

Scripts, Performance & WordPress Themes

WordPress performance and optimization starts at the code. Long before I consider caching, and even before I think about things like image optimization, I’m looking at the code behind the site. One of the areas I most often see “under optimized” is in script and style loading and it shouldn’t be since the time investment to optimize is minimal.

Here are a couple of very, to moderately easy methods for ensuring that your scripts and styles are being served in a way that allows you to squeeze a little extra performance out of your theme. (In some cases a lot extra.)

(more…)

Anchor Links and Hashed Urls with Genesis Custom Post Class

Here is a simple way to use the Genesis custom post class field to set up a nice little anchor link and hashed url.

Background
Recently I was involved in a project where the about (team) page required a nice smooth scroll that would link an employee’s headshot to an anchored position further down the page where more info about the employee could be found. We also wanted to keep in place a nice human readable hash so that the bio could be linked to directly (for those of you asking why we’re not using the_ID() to accomplish this).

With a few anchor links and a little jQuery this is typically pretty easy to pull off but it gets a little more challenging when you have consider the loop and intend to keep things dynamic.

After exploring Genesis and racking my brain for a bit I came up with a pretty decent solution.

(more…)

Swapping Sidebars in a Genesis Template

If you do any sort of complex development using the Genesis framework you will likely find yourself requiring additional sidebars outside of the packaged primary and secondary sidebars. Typically I’d recommend using the Genesis Simple Sidebars plugin.

But for some that might seem like overkill when you only require a single additional widget area on a single page template, and for that purpose I’d agree. This is how I handle swapping out sidebars in a Genesis child theme.
(more…)

Display Attachment File Type in WordPress Theme

Let’s say we have a list of downloadable items listed on a post or page, case studies for example. To help the end user understand what they will be downloading we’d like to display a file type adjacent to a download link.

e.g. Click to Download | PDF

Background: In this particular example our Case Studies are going to be a custom post type and the file attachments (downloads) are going to be added to each individual custom post type using custom fields. These custom fields are generated using the excellent Custom Metaboxes and Fields for WordPress.

This bit of information is important because by using Custom Metaboxes and Fields we are able to easily retrieve the attachment ID, which is what we really need to make this work. (see this example)

So, keep that in mind, the following can be used as long as you have that attachment ID.

Explanation: The above assumes that we’re in a loop of some sort and have already retrieved our attachment id, e.g. $file_id = get_post_meta( get_the_ID(), '_my_download_id', 1).

Then we use wp_get_attachment_url( $file_id ); to get the url for our attachment. We need this to generate the actual download link but we also want to save it as a variable so that we can use it in the wp_check_filetype( $file_url ) function. wp_check_filetype() returns an array of values containing the extension and mime type.

We then use the $filetype variable to output the extension with $filetype['ext'].

I might expand on this a bit more in the future to explain in detail how this was used but there should be enough there to be potentially useful.

Add Tax ID Column to WordPress Taxonomy Admin Columns

Problem: In a recent WordPress project we needed to provide an easy way for the site manager to locate the numerical ID associated with a custom taxonomy.

As WordPress developers we have a handful of methods at our disposal to recover that ID  but those options are not always that easy to explain to our clients.

So let’s make it easier.
(more…)