Hi…Im trying to set up the code so that the_field can link to an external url page.
For example, I created a field to put the name of the photographer of any feature image that I use within posts….So, i’m required to give them a link back to their URL.
This is the code I currently have to display this:
<p class="image_photographer">Image Courtesy of: <?php the_field('image_photographer'); ?></p>
I have linked to post pages before, but…im not sure how to get this to work for external page urls….also, I would need to make it redirect in popup window…so, it doesn’t take the visitor away from my site.
Can you please help…i would appreciate it! 🙂
Thanks for the reply!….Actually, that was my fault – the photographer name doesnt use the repeater…Thanks for noticing that.
Also, I think i need to clarify regarding the URL…I’m actually trying to have the name of the Photographer be a hyperlink to a specified url…Each post may have a different photographer….so, I may have something backwards in how I setup my field and code.
Currently, in the admin for the post – I have the field to type the name of the photographer, but I assume I also need the option to include a URL associated the name.
The field type that I am currently using is “Text”.
Below is an example of the code I am using now, which does make the Photographers name clickable – but, now how do I associate a specific URL?
I left a gap in the code on purpose, coz I assume that is where I fill in the missing code…right?
<p class="image_photographer">Image Courtesy of: <a href="[URL FIELD CODE GOES HERE]; ?>" target="_blank"><?php the_field('image_photographer'); ?></a>
Hopefully, you can see what I did wrong there, and what im trying to do
Hi @elliot — This was solved, but just had one quick question related to this…The code above is working perfectly, but I noticed if I put the Photographers Name, without a URL — the Photographers Name will still be a hyperlink & it will reopen the same post page its on…Is there a way, that if I do not include a URL, that it will only display the Photographer name as plain text, and not as a hyperlink?
Hope that makes sense. thanks.
This is called a conditional statement:
<?php $url = get_field('photographer_url'); ?> <p class="image_photographer">Image courtesy of: <?php if( $url ): ?><a href="<?php echo $url; ?>"><?php endif; ?> <?php the_field('image_photographer') ?> <?php if( $url ): ?></a><?php endif; ?></p>
The topic ‘Link to External URLs?’ is closed to new replies.
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!
10 years ago, a little plugin called Advanced Custom Fields popped onto the https://t.co/79Y5uWU7lY repository hoping to help a few like-minded developers.— Advanced Custom Fields (@wp_acf) May 31, 2021
Those “few” grew to 2M 📈🎉
Join us in celebrating 10 brilliant years with 10 tweets of brilliant features found in ACF! pic.twitter.com/oT1HPjdygF
© 2021 Advanced Custom Fields. Subscribe