Home › Forums › Backend Issues (wp-admin) › Display custom field value on edit page › Reply To: Display custom field value on edit page
Here is a filter that can be adjusted by field type and field name. You can adjust the HTML output as needed.
<?php
// change the field type to the type
// of field you want this run on
// use priority of 1 for before field
// use priority of 20 for before field
add_action('acf/render_field/type=url', 'field_name_render_url_image', 20, 1);
// change the function name to something unique
function field_name_render_url_image($field) {
// change $field name to
// the field to add the image to
$field_name = 'the_field_name';
if ($field['_name'] != $field_name) {
// not our field
return;
}
// uncomment this if you want to see value of $field
//echo '<pre>'; print_r($field); echo '</pre>';
// get the post id
global $post;
$post_id = $post->ID;
// get the current value of the field
// using get_post_meta to avoid confilcts
$url = get_post_meta($post_id, $field_name, true);
if (!$url) {
// nothing has been entered
?><p>Enter a URL and Update to View.</p><?php
return;
}
// make sure the url is an image
// alter regex to change allowed image extensions
if (!preg_match('/\.(jpg|jpeg|png|gif)$/i', $url)) {
// not an image we want to allow
?><p>The Entered is Not A Valid Image URL. Enter a Valid Image URL and Update to View.</p><?php
return;
}
// if we get here then show the image
?>
<img src="<?php echo $url; ?>" />
<?php
} // end function field_name_render_url_image
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.