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 2 years, 11 months ago.

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

Crovess

Hi Marcel,

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

Thanks and Happy Holidays!

Kevin

26 December 2011 at 10:16 #1965

Marcel

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

Crovess

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.

Example:

custom field = post_image
value = http://www.domain.com/wp-content/uploads/image.jpg

26 December 2011 at 10:32 #1967

Marcel

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 2 years, 11 months ago by  Marcel. Reason: Forgot seme-colon
26 December 2011 at 10:45 #1969

Crovess

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

Marcel

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

Crovess

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

This is my functions.php file – http://pastebin.com/XhhBR7Kp

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

Marcel

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

Marcel

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

26 December 2011 at 16:12 #1975

Crovess

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.