Reputation: 7941
I'm trying to add Outbrain widget to my Wordpress blog and the code is:
<div class="OUTBRAIN" data-src="DROP_PERMALINK_HERE" data-widget-id="XX_1" data-ob-template=“NameGoesHere”></div>
<script type="text/javascript" async="async" src="http://widgets.outbrain.com/outbrain.js"></script>
The problem is if I add this into the single.php, I can easily do it using <?php the_permalink(); ?>
in place of DROP_PERMALINK_HERE
. But I want to add the widget as a Wordpress widget and the text widget in Wordpress allows only HTML and PHP won't run there. So what do I do?
Get the URL of the page through Javascript? Or is there a better way?
Kindly guide.
Upvotes: 0
Views: 579
Reputation: 11
This is absolutely very easy to do.
All you need is a Header and Footer plugin. With this, you can add the Outbrain code (Widget) to your blog easily. - Just paste the code in the post-tab of the header and footer.
Upvotes: 0
Reputation:
If you would like to run PHP code in wordpress text widget then you have to paste below code in you active theme's functins.php file.
function php_execute_widget($html){
if(strpos($html,"<"."?php")!==false){
ob_start(); eval("?".">".$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}
add_filter('widget_text','php_execute_widget',100);
Upvotes: 1