@the-dude-1, thank you for downloading.
The link field actually returns an array value, not a single string value.
array(
[url] => http://site.com/page/
[title] => Page!
[target] => 0
)
So you can get the value you need by using something like this:
$link = get_field('my_link');
echo sprintf('<a href="%s">%s</a>', $link['url'], $link['title']);
Hi Corey,
thanks for the hint, but where should i integrate the code? Should i change your plugin-code?
And why does it not work out of the box, like i assumed? I thought, i enter Link and Link text in the ACF-backend, and see the linked text at the front end.
Cheers 🙂
-
This reply was modified 9 years, 3 months ago by
The-Dude.
@the-dude-1,
It does work out of the box, just not the way you are expecting. The code above can be placed in your theme template file, or anywhere you are trying to display the value.
ACF uses the function get_field to display a value: https://www.advancedcustomfields.com/resources/code-examples/
The Link field behaves just the same as an Image or File field would, they all return an array from the get_field function. https://www.advancedcustomfields.com/resources/file/
Ah, ok. That’s not what i want. Perhaps it implement it into the theme, all the work and information is gone with next theme update.
I thought it behaves and i can use it like the other ACF fields: Define it in a field group, fill in the information in the backend and see the result in the front end. No coding.
-
This reply was modified 9 years, 3 months ago by
The-Dude.
@the-dude-1,
That is how it works, but your theme must support it. And to make changes to a theme without updates overwriting them, you must create/use a child theme.
If you are using a commercial theme, I would contact them regarding the issue to see if they can add support for this ACF field type.
Thanks for this important hint. Yes, i’m using a commercial theme (and a child them of course ;)) that comes with ACF. Ok, then i talk to the theme developers. 🙂
You’re welcome! Hope they can help you get it figured out.