1

My code:

    // 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' );

The information is stored, convinently with the Options page named Options. The goal is to create a mini-plugin for a floating DIV on the page in which the shortcode is placed. Dandy.

I can't quite find the problem right now, and I'd appreciate knowing what am I doing wrong in returning the HTML tags with the various retrieved variables.

9
  • Replace your the_field by get_field, because the first display, and the second returns Commented Jun 8, 2016 at 8:26
  • I'm afraid the website still crashes when I add this code to the functions.php ... Still thanks for the Explenation! Commented Jun 8, 2016 at 8:29
  • I think the first argument of add_shortcode should not contain special chars (like spaces) Commented Jun 8, 2016 at 8:31
  • And you have an error here : <a href=". ' $nLink ' . " (the dots are poorly positioned). Commented Jun 8, 2016 at 8:34
  • I've changed that, still no luck, but at least i'm cleaning it off. Thanks again! Commented Jun 8, 2016 at 8:34

1 Answer 1

3

Here is your corrected code :

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>';
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.