Search code examples
wordpresssmarty

How to run php code in smarty template file?


I want to load wordpress in a smarty template. I used the code below to load wordpress in a php file and it worked. But it is not working a smarty template.

In php file:

<?php
include $_SERVER['DOCUMENT_ROOT'].'/wordpress/wp-load.php';
get_header();
?>

In smarty template file:

{php}
include $_SERVER['DOCUMENT_ROOT'].'/wordpress/wp-load.php';
get_header();
{/php}

Solution

  • Are you using Smarty3? Have a look here.

    {php} tag is deprecated, and from version 3.1 it's only available using SmartyBC class instead of Smarty class. They are just the same, but if you instance a new SmartyBC() object you will have a backward-compatible Smarty object supporting {php} tags.