Home > Enterprise >  Why this is showing me nothing in Wordpress?
Why this is showing me nothing in Wordpress?

Time:09-16

Why this is show me nothing?? I'm totally lost =(

function calc_shortcode(){ ?>
<div>
    <form>
        <h3>Price High</h3>
        <input name="priceHigh" type="text" />
        <h3>Price Low</h3>
        <input name="priceLow" type="text" />
        <h3>Price Up</h3>
        <input name="priceUp" type="text" />
        <h3>Price Down</h3>
        <input name="priceDown" type="text" /></br>
        <input name="submit" type="submit" value="Calculate" class="btn btn-primary" />
    </form>
</div>
<?php 
} 

add_shortcode('calc_pat', 'calc_shortcode'); 

Thanks for helping guys!

CodePudding user response:

The php labels are wrongly placed there, try doing this:

<?php
function calc_shortcode(){ 
<div>
    <form>
        <h3>Price High</h3>
        <input name="priceHigh" type="text" />
        <h3>Price Low</h3>
        <input name="priceLow" type="text" />
        <h3>Price Up</h3>
        <input name="priceUp" type="text" />
        <h3>Price Down</h3>
        <input name="priceDown" type="text" /></br>
        <input name="submit" type="submit" value="Calculate" class="btn btn-primary" />
    </form>
</div>
 
} 

add_shortcode('calc_pat', 'calc_shortcode');
?>

Check if that works

CodePudding user response:

Please give try to below code, it should work:

function calc_shortcode(){ 
echo '<div>
    <form>
        <h3>Price High</h3>
        <input name="priceHigh" type="text" />
        <h3>Price Low</h3>
        <input name="priceLow" type="text" />
        <h3>Price Up</h3>
        <input name="priceUp" type="text" />
        <h3>Price Down</h3>
        <input name="priceDown" type="text" /></br>
        <input name="submit" type="submit" value="Calculate" class="btn btn-primary" />
    </form>
</div>';
} 

add_shortcode('calc_pat', 'calc_shortcode');

you can also add ob_start(); and ob_get_clean();

CodePudding user response:

To use shortcode you need to call it. Read more here https://developer.wordpress.org/reference/functions/add_shortcode/ and https://developer.wordpress.org/reference/functions/do_shortcode/

echo do_shortcode('[calc_pat]'); 
  • Related