Normally, you will use shortcodes inside content areas like posts, pages, or sidebar widgets. However, sometimes, you may want to add a shortcode inside your WordPress theme.
In this article, we will show you how to easily add any shortcode to your WordPress theme.
functions.php
function shortcode_fun(){
return 'this is custom shortcode';
}
add_shortcode('sc', 'shortcode_fun');
functions.php
function shortcode_fun(){
?>
<div class="container">
<form action="/action_page.php">
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
<?php
}
add_shortcode('sc', 'shortcode_fun');
page.php
<?php echo do_shortcode("[sc]"); ?>
in wordpress page editor
[sc]