使用WordPress高级自定义字段时'url'的字符串偏移量非法 [英] Illegal string offset for 'url' when using WordPress Advanced Custom Fields

查看:106
本文介绍了使用WordPress高级自定义字段时'url'的字符串偏移量非法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Bootstrap模板转换为WordPress主题。



对于自定义字段,我正在使用插件



如果它设置为array选项,您可以像目前这样访问 url ,还可以访问与图像有关的一系列其他数据(例如宽度)和高度,WordPress附件ID,输入的标题等)。


I am converting a Bootstrap template into a WordPress theme.

For custom fields I am using the plugin Advanced Custom Fields. The issue is when I am trying to add an image with the help of Advanced Custom Fields, I get the following error:

Warning: Illegal string offset 'url' in C:\wamp64\www\my-site\wordpress\wp-content\themes\bootstraptowordpress\page-home.php on line 31

However when I am adding text through this plugin it shows no error.

I have no other plugins installed other than ACF.

Here is my code:

$home_page_logo = get_field('home_page_logo');

<div class="front_logo">

   <?php if( !empty($home_page_logo)): ?>

      <img src="<?php echo $home_page_logo['url']; ?>" alt="<?php  echo $home_page_logo['alt']; ?>" />

   <?php endif; ?>

 </div>

解决方案

There are three ways that an image field can be returned in ACF (array, URL, or ID). It sounds like your field is set to return the URL - which returns as a string.

Therefore, you need to access it like this:

<?php echo $home_page_logo; ?>

instead of this:

<?php echo $home_page_logo['url']; ?>

Alternatively, you can edit the set up for the field in your WordPress admin and configure it to return an image array instead of the URL:

If it's set to the array option, you can access the url like you are currently doing so, as well as access a range of other data pertinent to the image (such as its width and height, WordPress attachment ID, caption if entered, etc.)

这篇关于使用WordPress高级自定义字段时'url'的字符串偏移量非法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆