Adding the Facebook Like button to a WordPress site is straightforward for standard themes—you can insert the markup into header.php and single.php. For frameworks like Thesis and Genesis, the recommended approach is to add the code using theme functions so it integrates cleanly with the framework’s hooks.
Some users rely on plugins that let you inject PHP via the WordPress admin interface (for example, plugins that provide open-hook functionality). While those can be convenient, I recommend avoiding them unless you are confident with PHP. A small typo in injected PHP can break the site and make it difficult to log in to fix the issue.
Below are examples that place the Facebook Like button directly above single post content. If you prefer a different placement, use a visual hook reference for your framework to choose the appropriate hook for your theme.
Facebook Like in Thesis
For Thesis, add the following to your custom_functions.php. The code does two things: it prints the Like iframe when viewing a single post, and it adds Open Graph meta tags into the head so Facebook picks up the correct title, site name and image.
';
}
}
add_action( 'thesis_hook_before_post', 'facebook_like_single' );
// Add Open Graph tags to the document head
function facebook_like_head() {
if ( is_single() ) {
global $post;
echo '';
} else {
echo '';
}
// Change the image path to match your theme if needed
echo '';
echo '';
}
add_action( 'wp_head', 'facebook_like_head' );
?>
Notes for Thesis:
- The facebook_like_single function checks is_single() so the Like button only appears on individual posts, not on archives, category pages, or the homepage.
- The facebook_like_head function injects Open Graph meta tags. When viewing a single post it outputs the post title; otherwise it falls back to the site name and description. It also specifies an image (example path: /custom/images/logo.jpg). If you want a different image, update that path accordingly.
Facebook Like in Genesis
For Genesis child themes, add the following to functions.php. The logic and purpose are the same as the Thesis example, but the hook used to output the Like button differs to match Genesis hook names.
';
}
}
add_action( 'genesis_before_post_content', 'facebook_like_single' );
// Add Open Graph tags to the document head
function facebook_like_head() {
if ( is_single() ) {
global $post;
echo '';
} else {
echo '';
}
// Update the image path to match your child theme structure
echo '';
echo '';
}
add_action( 'wp_head', 'facebook_like_head' );
?>
Notes for Genesis:
- The facebook_like_single function is attached to genesis_before_post_content so the Like iframe appears above the post content on single posts.
- The facebook_like_head function outputs Open Graph meta tags. It uses the post title on single posts and falls back to site title and description elsewhere. The example uses /images/logo.jpg inside the child theme directory for the og:image tag—change that path to the image you prefer.
Additional tips:
- Always back up your functions.php or custom_functions.php before editing. A small syntax error can cause fatal errors that prevent access to the admin area.
- Use esc_url, esc_attr and urlencode where appropriate to ensure URLs and attributes are properly encoded and safe.
- Test the Open Graph output using Facebook’s Sharing Debugger (or similar tools) to confirm Facebook reads the correct title, image and site name.
With these additions, your single posts will show a Facebook Like button above the content and include the basic Open Graph tags Facebook expects for better sharing results. Adjust image paths and hook placement as needed to match your theme structure and design preferences.