Home › Forums › General Issues › Field to show an Image? › Reply To: Field to show an Image?
You’ve put the code in the right place, but you’ll need to make some modifications.
The filter does not create a new field type. It alters the behavior of an exiting field. In this case the URL field type.
If you want to use a text field the first thing that needs to be changed is the field type. On line 11 where the filter is added change acf/render_field/type=url
to acf/render_field/type=text
.
The next thing you’ll need to do is replace some of the values with the name of your field. The name of the function should be changed to the include your field name instead of "field_name"
and then name of your field needs to replace the value of $field_name
on line 16.
The last thing you’ll need to do is change validation on line 36. The reason that I chose a URL field for the example is that ACF already validates these fields to make sure they are valid URLs and the only thing that I’m checking for is that they URL ends with an image type extension.
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.