将选项页面 ACF 数据添加到 Functions.PHP 中的 Wordpress 短代码

Adding an Option Page ACF data to Wordpress Shortcode in Functions.PHP

我的代码:

    // Add Shortcode
function NavotFloatingDiv() {
    $nHeight = the_field('distance_from_top', 'options');
    $nPadding = the_field('div_padding', 'options');
    $nBackgroundColor = the_field('div_background_color', 'options');
    $nDisplay = the_field('div-display', 'options');
    $nDirection = the_field('left-right', 'options');
    $nLink = the_field('divlink', 'options');
    $nTarget = the_field('divlinktarget', 'options');
    $nLinkTitle = the_field('divlinktitle', 'options');
    $nContent = the_field('floating_div', 'options');
    return '<div id="Navot-Float" class="NavotFlaot" style="z-index: 99999999999; position: fixed; padding:' . $nPadding . 'px; background-color:'. $nBackgroundColor .' ; display: ' . $nDisplay . '; ' . $nDirection . ': 0px ;  top: '. $nHeightheight . '%;"><a href=". ' $nLink ' . " target=" ' . $nTarget .' " title=" '. $nLinkTitle .' "><div class="floater-navot-text"> ' . $nContent . '</div></a></div>';

}
add_shortcode( 'Floating DIV', 'NavotFloatingDiv' );

信息已存储,方便地使用名为选项的选项页面。目标是为放置短代码的页面上的浮动 DIV 创建一个迷你插件。花花公子。

我现在还不能完全找到问题所在,如果知道我在返回带有各种检索变量的 HTML 标签时做错了什么,我将不胜感激。

这是您更正后的代码:

add_shortcode('floating_div', 'NavotFloatingDiv');
function NavotFloatingDiv(){
    $nHeight          = get_field('distance_from_top', 'options');
    $nPadding         = get_field('div_padding', 'options');
    $nBackgroundColor = get_field('div_background_color', 'options');
    $nDisplay         = get_field('div-display', 'options');
    $nDirection       = get_field('left-right', 'options');
    $nLink            = get_field('divlink', 'options');
    $nTarget          = get_field('divlinktarget', 'options');
    $nLinkTitle       = get_field('divlinktitle', 'options');
    $nContent         = get_field('floating_div', 'options');
    return '<div id="Navot-Float" class="NavotFlaot" style="z-index: 99999999999; position: fixed; padding:'. $nPadding . 'px; background-color:'. $nBackgroundColor .' ; display: ' . $nDisplay . '; ' . $nDirection . ': 0px ;  top: '. $nHeightheight . '%;"><a href="'. $nLink .'" target=" ' . $nTarget .' " title=" '. $nLinkTitle .' "><div class="floater-navot-text"> ' . $nContent . '</div></a></div>';
}