Skip to main content

Save HTML Content To Variable In WordPress And Call Anywhere

By March 29, 2017Blog, CMS, Wordpress
WordPress Tutorials by Allure Web Solutions

Sometimes we may want to display a block or snippet of HTML inside our WordPress theme or plugin. We can save this snippet to a PHP variable and call it anywhere, inside or outside a loop.

<?php ob_start(); ?>
  <span>Your HTML goes here</span>
<?php $html = ob_get_clean(); ?>

Now you call the $html variable anywhere in your code.


Author allure

More posts by allure

Leave a Reply

Designed by

best down free | web phu nu so | toc dep 2017