Create WordPress shortcode to print out HTML on pages and posts

 In Functions, Media, Shortcode

Create WordPress shortcode to print out HTML on pages, posts and text widgets

Sometimes we want to display the same html content severals times on the website, we can either copy past the html content and added to the WordPress text editor which most of the times works or we can just create a WordPress shortcode to display the html content.

Using WordPress shortcode we can avoid having the text editor full of html code which sometimes could be very painful to work out 🙂

Add this code below on your theme functions.php and use this shortcode [test_print_shortcode] on your posts, pages text widget.

Note : the function name needs to be changed to something more meaningful.

Create WordPress shortcode to print out HTML on pages, posts and text widgets code snippet:

function   ns_shortcode_html() {
 ob_start();

  ?>
  <div class="event__inner_header">
    <h3 style="text-align:center;">THANK YOU !</h3>
  </div>
 <?php

 return ob_get_clean();
}
add_shortcode( 'test_print_shortcode', 'ns_shortcode_html' );

You can find more info about the Shortcode API here.

Thank you for seeing my tutorial and fell free to share and comment 🙂 . Do you have a code snippet and you want to see it publish on my site ? I will be more than happy to do it please send me a message here. 

Recent Posts

Leave a Comment

Start typing and press Enter to search

Let's work together!