ControlledChaos
5/7/2015 - 8:29 AM

Allow PHP in WordPress Text Widgets

Allow PHP in WordPress Text Widgets

<?php

function ccd_php_text_widgets( $text ) {
  
  if ( strpos( $text, '<' . '?' ) !== false ) {
    ob_start();
    eval( '?' . '>' . $text );
    $text = ob_get_contents();
    ob_end_clean();
  }
  
  return $text;

}
add_filter( 'widget_text', 'ccd_php_text_widgets', 99 );

?>

Allow PHP in WordPress Text Widgets

WordPress Snippet