首页 > 解决方案 > How to print custom field value inside shortcode Wordpress

问题描述

I'm trying to print a Custom field value inside the shortcode I have, I tried the following code but it's not working for me ... what's i can do to make it print the value ?

<?php echo [mks_button size="large" title="Download Pdf File" style="rounded" url="(get_field('download_link')<>""?''.get_field('download_link').'':"");" target="_blank" bg_color="#1e73be" txt_color="#FFFFFF" icon="fa-file-pdf-o" icon_type="fa" nofollow="1"]'); ?>

Note: The Value i want to print inside the url Attribute

标签: phpwordpress

解决方案


尝试。

$url = get_field('download_link');

if($url){
    echo do_shortcode('[mks_button size="large" title="Download Pdf File" style="rounded" url="'. $url .'" target="_blank" bg_color="#1e73be" txt_color="#FFFFFF" icon="fa-file-pdf-o" icon_type="fa" nofollow="1"]'); 
}

推荐阅读