Skip to content

Instantly share code, notes, and snippets.

@eteubert
Created November 18, 2011 15:25
Show Gist options
  • Select an option

  • Save eteubert/1376742 to your computer and use it in GitHub Desktop.

Select an option

Save eteubert/1376742 to your computer and use it in GitHub Desktop.
WordPress: Shortcodes in Text Widgets
ericteubert: ~/Sites/wordpress-single
➜ ack widget_text
wp-admin/includes/schema.php
307: 'widget_text' => array(),
wp-content/plugins/ikonum/class/class.custom-field-template.php
101: add_filter('widget_text', 'do_shortcode');
wp-includes/default-widgets.php
371: $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
379: $text = apply_filters( 'widget_text', $instance['text'], $instance );
wp-includes/widgets.php
405: 'wp_widget_text',
406: 'wp_widget_text_control',
<?php
function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
global $wp_filter, $merged_filters;
$idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
$wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
unset( $merged_filters[ $tag ] );
return true;
}
<?php
function do_shortcode($content) {
global $shortcode_tags;
if (empty($shortcode_tags) || !is_array($shortcode_tags))
return $content;
$pattern = get_shortcode_regex();
return preg_replace_callback('/'.$pattern.'/s', 'do_shortcode_tag', $content);
}
<?php
add_filter( 'widget_text', 'do_shortcode' );
<?php
add_filter( 'widget_title', 'do_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment