dannyJuna
dannyJuna

Reputation: 1

Why this is showing me nothing in Wordpress?

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

<?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>
<?php 
} 

add_shortcode('calc_pat', 'calc_shortcode'); 

Thanks for helping guys!

Upvotes: 0

Views: 41

Answers (4)

anujpatel
anujpatel

Reputation: 141

Try below code :

<?php function calc_shortcode()
{
    ob_start();
?>
    <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
    echo ob_get_clean();
    die();
}

add_shortcode('calc_pat', 'calc_shortcode');

Upvotes: 0

Snuffy
Snuffy

Reputation: 2096

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

Upvotes: 1

ZealousWeb
ZealousWeb

Reputation: 1751

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();

Upvotes: 0

Adrian Estevez
Adrian Estevez

Reputation: 13

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

Upvotes: 0

Related Questions