Skip Navigation

[Resolved] Show custom field images as clickable links

This thread is resolved. Here is a description of the problem and solution.

Problem: I have two custom fields on a post. One is a URL field, and the other is an image field. On the front-end, I would like to show the image as a clickable link, pointing at the URL.

Solution:
Construct an HTML link tag using the raw website field as the href value and the logo field as its contents:

<a href="[types field='website' output='raw'][/types]">[types field='logo'][/types]</a>

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/functions/#image
https://toolset.com/documentation/customizing-sites-using-php/functions/#url

100% of people find this useful.

This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 10 replies, has 2 voices.

Last updated by StephenD4019 6 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#610414

Go to the company information page.

Click on a company - for example AA

When you click through to the page, there is a logo and then a go to website link.

Please can you clearly advise me how I can make this image a clickable link so that it opens a new tab and takes the user to the page which is on the go to website link please?

I want to have the image and the Go to website both clickable links to the same page on a new tab.

#610498

If the image is saved as an image custom field, and the link is saved as a URL custom field, you can construct a linked image tag in HTML like this:

<a href="[types field='url-field-slug' output='raw'][/types]">[types field='img-field-slug'][/types]</a>

Replace 'url-field-slug' with the slug of your link URL field (including the single quotation marks). Then replace 'img-field-slug' with the slug of your image field (including the single quotation marks). This is a very basic implementation, but you get the idea. Here's the documentation for the Types field shortcodes:
https://toolset.com/documentation/customizing-sites-using-php/functions

If this doesn't work as expected, please let me know and we can take a closer look.

#610502

Hi,

Thanks for your reply.

I changed the line which was originally:

<div>[types field='logo'][/types]</div>

TO

<div>[types field=''logo''][/types]</div>

The slug for the URL link to the website is 'website' and the slug for the logo is 'logo'

When I go to the company page the logo does not appear and therefore is not clickable.

#610503

Sorry it didn't paste correctly. I changed it to:

<div>[types field=''logo''][/types]</div>

#610531

Okay please add this code so we can test each individual piece of the puzzle and figure out what's going wrong:

<div>
  Test URL: [types field='website' output='raw'][/types]<br />
  Test <a href="[types field='website' output='raw'][/types]">link</a><br />
  Test image: [types field=''logo''][/types]<br />
  Test link image: <a href="[types field='website' output='raw'][/types]">[types field='website' output='raw'][/types]</a>
</div>

- Is the Test URL correct?
- If you click the Test link, does it send you to the right location?
- Is the Test logo shown as expected?
- Is the Test link image still broken? I modified some of the quotation marks to use preferred formatting.

#610891

I added the code but nothing shows. All it shows is what was on the page excluding the origina logo and nothing from the new code.

Aviva Edit

Go to website

Aviva
8 Surrey Street
Norwich
NR1 3NG

#610904

May I log in to your wp-admin area to see what's going on? Please provide login credentials here in the private reply fields, and let me know which URL I should visit to see the problem. I will take a look and give you some feedback.

#611487
Screen Shot 2018-01-31 at 11.03.42 AM.png

It looks like the code I provided was transformed somehow when you copy+pasted it into your Layout's Visual Editor. Some of the quotation marks were converted into HTML equivalent characters. You can see this in the attached screenshot like this (with no spaces):

& #039;

I have made the proper changes for you to convert those back to the proper quote mark syntax. I see the logo appearing as a clickable link now on the AA page. Can you confirm?

#611490

That's fine. Thanks.
I have just added target="_blank" to try to get the page to open in a new tab when you click the link but this doesn't appear to be working.

Thanks.

#611504

Move the target="_blank" to the "a" tag. Right now it's applied to the Types field shortcode, which won't help you. It must be applied to the "a" tag itself to affect the link behavior.

#611578

Thanks.