Create WordPress shortcode to print out HTML on pages and posts

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)

ABOUT AUTHOR

Nuno

I am a Freelance Web Developer and WordPress Expert based in London with a wealth of website development and support experience. I am great at problem solving and developing quick solutions.

LEAVE A COMMENT

Your email address will not be published. Required fields are marked *

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

  • LET'S TALK!

    Fill in the form below to make an enquiry or find my contact details on my contact page.

  • This form collects your name and email address 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.