我如何使高级自定义字段成为链接?

问题描述 投票:0回答:1

我在WooCommerce的产品页面上具有以下代码的自定义字段

add_action('woocommerce_single_product_summary', 'subtitle_link', 15);

function subtitle_link() {
    global $post;
    $subtitle = get_post_meta($post->ID, 'link', true);
    if(!empty($subtitle)){

        echo __("\n<br />\n<br />Enter this competition for free:", '');
        echo '<h3>'.$subtitle.'</h3>';

    }
}

尽管此显示应在前端显示,但该URL不是链接。

wordpress woocommerce advanced-custom-fields
1个回答
0
投票
function subtitle_link() {
    global $post;

    // Make sure this works!
    $subtitle = get_post_meta($post->ID, 'link', true);

    // If the above works, remove this!
    $subtitle = 'http://www.google.com';

    if( $subtitle ) {
        echo __("\n<br />\n<br />Enter this competition for free:", '');
        echo "<h3><a href='" . $subtitle . "'>My url</a></h3>";
    }
}
add_action('woocommerce_single_product_summary', 'subtitle_link', 15);
© www.soinside.com 2019 - 2024. All rights reserved.