How to Use Link Picture from Custom Field

Index Forums WordPress plugins Add Link to Facebook How to Use Link Picture from Custom Field

This topic contains 9 replies, has 2 voices, and was last updated by  Crovess 3 years, 9 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
Author Posts
Author Posts
26 December 2011 at 09:47 #1964


Hi Marcel,

How do I use the link picture from value in custom field “post_image”?

Thanks and Happy Holidays!


26 December 2011 at 10:16 #1965


If you mean the post meta box of Add Link to Facebook:

  • Upload an image
  • Update the post
  • Select the image in the meta box
  • Update or publish the post
26 December 2011 at 10:26 #1966


No I mean automatically pulling images from a custom field called “post_image”. Because the only way I can add a featured image with my theme is by adding it into custom field.


custom field = post_image
value =

26 December 2011 at 10:32 #1967


You will need some custom code for this:

add_filter('al2fb_picture', 'al2fb_custom_picture' 10, 2);
function al2fb_custom_picture($picture, $post) {
	return get_post_meta($post->ID, 'post_image', true);

I have not tested this, but it should work.
You should put this in the functions.php of your theme.

  • This reply was modified 3 years, 9 months ago by  Marcel. Reason: Forgot seme-colon
26 December 2011 at 10:45 #1969


Great! I’ll give it a try.

By the way can you add an option that supports custom field in the next update? Say, a new option that lets users manually input the custom field they want to pull the image from. This would be great for those who use a theme that can only add featured images through custom fields. Just a suggestion though.

26 December 2011 at 10:48 #1970


WordPress has a built-in function for featured images, which is supported by Add Link to Facebook, so I see no reason to support non-standard ways to add featured images. IMHO it is better to ask your theme developer to support the built-in WordPress function.

26 December 2011 at 10:59 #1971


I’m sorry Marcel but where should I place the code?

This is my functions.php file –

Also, which option should I use in the AL2FB’s link picture settings page?

1. WordPress Logo
2. First Attached Image
3. Featured Post Image
4. Let Facebook Select
5. First Image in the Post
6. Avatar of Author
7. Custom Picture Below

I guess Featured Post Image?

26 December 2011 at 11:47 #1972


Just insert it at line 12 and use this code:

add_filter('al2fb_picture', 'al2fb_custom_picture', 10, 2);
function al2fb_custom_picture($picture, $post) {
	$post_image = get_post_meta($post->ID, 'post_image', true);
	return (empty($post_image) ? $picture : $post_image);

In this way you can select ‘First Image in the Post’ as a backup in case there is no featured image.

26 December 2011 at 11:48 #1973


Be aware that this code will be overwritten by a theme update.

26 December 2011 at 16:12 #1975


It works like a charm! Thanks so much for your help!

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘How to Use Link Picture from Custom Field’ is closed to new replies.