显示一个用于获取用户元数据的图标。

huangapple go评论54阅读模式
英文:

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, &#39;g_website&#39;, true );

if ( ! empty( $g_website ) ) {
    $website_icon_url = &#39;&#39;; // Set image icon URL.

    printf( 
        &#39;&lt;div&gt;&lt;a href=&quot;%s&quot;&gt;&lt;img src=&quot;%s&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&#39;,
        esc_url( $g_website, array( &#39;http&#39;, &#39;https&#39; ) ),
        esc_url( $website_icon_url, array( &#39;http&#39;, &#39;https&#39; ) )
    );
}

huangapple
  • 本文由 发表于 2023年6月6日 01:57:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76408903.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定