我目前正在编辑一个带有自定义字段输出的WordPress主题。
我已经成功地进行了所有编辑,并且一切都按照预期工作。
我的问题是,如果将URL提交到自定义字段中,则回显恰好是其中的内容,因此如果有人输入 www.somesite.com ,则回显就是这个并将其添加到域的末尾:www.mysite.com www.somesite.com 。
我想检查所提供的链接是否以http://
前缀开头,如果有,则不做任何处理,但如果没有,则在网址之前回显http://
。
我希望我已经很好地解释了我的问题。
$custom = get_post_meta($post->ID, 'custom_field', true);
<?php if ( get_post_meta($post->ID, 'custom_field', true) ) : ?>
<a href="<?php echo $custom ?>"> <img src="<?php echo bloginfo('template_url');?>/lib/images/social/image.png"/></a>
<?php endif; ?>