The Blacksmiths Blog is the behind the scenes, more technical side of website development that we just can't help but share.

If you are into geeky hackery, you are in the right place. More casual users will probably want to stick to the Attention Engine Blog here.

Controlling the Facebook Image in WordPress


Controlling the image that Facebook pulls from a WordPress website can be a pain. You usually have only a few options:

1. Do nothing and let FB pull a random image.

2. Set an image in the header site wide. Predictable, but you won’t have the ability to set images per post or page.

3. Dynamically pull images from posts in a custom field or the featured image. Great for posts and pages, but not so good for the home page, archives, etc.

I’ve seen plugins that try to help with this but I’ve not found them reliable or they break.

Solution? Put this in  your header:

<meta property="og:image" content="
$image = get_post_meta($post->ID, 'image', true);

if (is_single() )
echo $image;
echo "";

?>" />

This code first checks to see if it’s on a single.php page. If it is and there is a image url in the custom field ‘image’, it will display that image for FB. If it’s not on a single.php page, it will display the default image. Best of both worlds. This way you can have blog posts show a unique image but the rest of your site will show an image you set, like your logo. Obviously don’t run a FB plugin that might conflict with this code.

Now for the custom field, many themes like Woo Themes have a custom upload area for a post image that spits out a meta id “image”. But you could create this yourself, for example using the Advanced Custom Fields plugin. You would need to replace ‘image’ with the id of your custom field.

If you’re somewhat new to php, here’s a brief explanation:

The first line of the code defines what $image means in this string of code (here it’s the custom field ‘image’). The second line checks to see if  it’s on a single.php page (an individual blog post). If it is, it spits out (echoes) the image from the custom field. If it’s not on a single.php page, it then goes to the last line of code which spits out your default image.

Moving up the stack


If you are like me, your dev started with the WordPress admin with themes and plugins, then moved in to FTP editing CSS and even php.

If you want to take your dev productivity up a notch, the command line is where it’s at. While intimidating at first, working at the command line is radically more powerful than anything you can do using the dashboard or FTP.

Here is a handy guide to help you get around in the Linux terminal.

Linux Cheat Sheet

Adding wordpress content only Admin’s can see


One of my favorite bits of code I use all the time is a very simple little function that makes it easy to only show content for user’s logged in as administrators. Most often I use this for 2 specific reasons:

  1. To leave useful little “notes” around the front end of the site so site owners can easily understand what each portion of their site does, and where it’s controlled from. Example, I create a custom template page that pulls a description from “the page” but pulls content from a custom post type. I can drop a little note in that displays a nice little gold box or something when the website owner is logged into wordpress and viewing their site.
  2. Testing out changes on a live site so if I’m dropping in a new opt in box, tweaking some css, or adding in a new block of content and it’s not “quite” ready yet, I as an admin can get a preview of what it’s going to look like without having to use a development site or worry about using a theme tester.

I’m sure there are many other uses out there as well!

if ( current_user_can( 'manage_options' ) ) { 
 /* Content a user with admin privileges sees */
 else {
    /* Content a user without admin privileges sees */

Adding a new wordpress admin account if all you have is FTP access


While recently helping a client fixed a hack site, I found myself in the unique situation where I had FTP access to the wordpress site, but was locked out of the WordPress admin account, and didn’t have MySQL access via PhpMyAdmin.

WordPress lists some great ways to reset the password on the codex, but the most useful one required knowing the user ID of the administrator account. I tried guessing a few times to no avail and needed to find a workaround.

Lucky for me, there is a simple and easy way to create a NEW administrator account in wordpress by doing nothing more than dropping this bit of code into the functions.php of your active theme. Paste it in, save, refresh your site in your browser, and VOILA!, access to wordpress with your new admin account allowing you to go in and clean up whatever needs to be handled.

function admin_account(){
$user = 'AccountID';
$pass = 'YourPassword';
$email = [email protected]';
if ( !username_exists( $user )  && !email_exists( $email ) ) {
        $user_id = wp_create_user( $user, $pass, $email );
        $user = new WP_User( $user_id );
        $user->set_role( 'administrator' );
} }

The economy of a website:
Is yours growing or in recession?


There is an economics to everything we experience online.

By this I mean that everything that happens on any website page is dictated by a scarcity of precious resource—a supply and demand.

This resource not monetary, but in fact something more precious and more fundamental.

The currency of your website is attention.

So how do we deal in attention?

The average user reads about 20% of the words on a page and stay on a any page for about 20 seconds(on the high end.)*

If that is the case, how do we deal with it if we want to get our message across, sell products or share content?

Simple…respect the attention.

Respect the fact that the most precious commodity of an information economy(like the one your website lives in) is, in fact, attention and build your site and your content accordingly.

Give your users exactly what they want…directly, clearly, cleanly.

Set your website priorities to maximize benefit and minimize confusion. Deliver the goods. Create a clear funnel of participation(more on this later.) And get to the point.

Consider that for every dollar and hour you spend creating something on your site, there will be a reciprocal amount of attention granted…and solve for that equation.

Do everything you can to increase
the ratio of $$:A (where A = Attention ;))

So how is your website economy doing? How do you know for sure? What are you tracking?

Stay tuned to the Vision category of the Blacksmiths Blog for solutions, suggestions and hacks to these questions and general strategies for website success.