英文:
Show an icon for a get_user_meta
问题
在我的网站上,我有一个成员列表,对于每个成员,我会显示一些信息。其中之一是网站URL。我想要将URL显示为图标,而不是实际的URL。网站地址是动态填充的。
如何在这里添加图标?我还将删除标签,只显示图标。谢谢
显示图标而不是完整的URL。
英文:
On my website I have a list of members and for each of them I display some info. One is the website URL. I would like to show the URL as an icon rather than the actual URL. The website address is dynamically populated by the
$g_website = get_user_meta( $user_id, 'g_website', true );
if ( ! empty( $g_website ) ) {
?>
<div><span class="label">Website: </span><?php echo esc_html( $g_website ); ?></div>
<?php
}
How can I add the icon here? I will remove the label as well and just show the icon. Thanks
Show the icon instead of the full URL
答案1
得分: 1
Here is the translated code portion:
$g_website = get_user_meta( $user_id, 'g_website', true );
if ( ! empty( $g_website ) ) {
$website_icon_url = ''; // 设置图标图片的 URL。
printf(
'<div><a href="%s"><img src="%s" /></a></div>',
esc_url( $g_website, array( 'http', 'https' ) ),
esc_url( $website_icon_url, array( 'http', 'https' ) )
);
}
英文:
Would be something like this (untested):
$g_website = get_user_meta( $user_id, 'g_website', true );
if ( ! empty( $g_website ) ) {
$website_icon_url = ''; // Set image icon URL.
printf(
'<div><a href="%s"><img src="%s" /></a></div>',
esc_url( $g_website, array( 'http', 'https' ) ),
esc_url( $website_icon_url, array( 'http', 'https' ) )
);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论