4

I'm currently working on a Wordpress website using the Advanced custom fields and WPBakery aka visual composer plugins.

While I manage to use these two plugins to post custom text, I have problems with images.

What I have tried so far is:

  1. use acf in plain text, but as expected this only displays the link, not the image

  2. using an image building block, but that won't work because there does not seem to be an option to link the image to a custom field

  3. using ACF-VC integrator and linking it to the custom field, this also only displays the image
  4. using an advanced custom field, also does not work.
  5. using raw html, also does not work.

(Screenshot of the 5 methods: and their output when creating the blog post: enter image description here)

The only working solution I found so far is to insert this line in the single.php file:

<img src="<?php the_field('associated_image'); ?>" alt="" />

When doing that, this is what the blog post shows. As you can see, it is the correct image that is displayed, and it has pulled the image from the link in the custom field.

enter image description here

Some additional information:

  • The custom image field is configured as a text field, as we pull automatically an image link from a file, so I can configure it to an image field, as we do not pull an image

  • One constraint that I have is that I should make use of WPBakery if possible and not work to much with raw php files, as it is very important that the work done should be easily maintainable, especially by people without an understanding of php.

What can I do to solve this problem? One possibility might be to add a function and shortcode in the functions.php file, but I do not manage to do that, as I have no real understanding of php.

I hope the formating of this post is at least acceptable, and if anyone is interedsted in helping I can provide additional details of course

charelf
  • 3,103
  • 4
  • 29
  • 51
  • did you try the plugin, that WPBakery made? https://wpbakery.com/addons/acf-in-vc/ – Stender Aug 01 '18 at 07:52
  • Not yet, but I managed to find another solution via the WPBakery Slack community, The person who helped me will post it shortly or I will, but thank you for your help. I also would not like to use to many plugins, as, as said, maintenance is a high priority and plugins might cause trouble – charelf Aug 01 '18 at 07:54
  • 1
    I agree - I wouldn't use to many plugins either, but then again - I never use Visual composer. So it was just a guess :) – Stender Aug 01 '18 at 08:13

1 Answers1

5

You can use the ACF shortcode to echo out the value of your custom field. So you can create a new text block element in Page Builder, then switch to the text tab (above the editing field to the right), and insert the following code

<img src="[acf field='field_name']">

When Page Builder outputs its content, it'll pass through the function 'do_shortcode()', where ACF will work its magic.

Fpckalk
  • 116
  • 5