Create WordPress shortcode to print out HTML on pages and posts

 In All, 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() {

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

 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Start typing and press Enter to search

Let's work together

I'd love to work with you! Please fill out my project form to tell me more about your project/work. I reply to all enquiries within 48 hours.


  • November - Booked
  • December - Booked
  • January - Available


  • My day rate is £300.
  • I can provide a fixed price for your work.

EN - Header Enquiry Form

  • This form collects your name, email address and telephone number so that I can respond to the enquiry(ies) that you submit via this website. Please check my privacy policy for the full story on how I use, protect and manage your submitted data.