Title: Shortcode doesn&#039;t work on text widget
Last modified: August 22, 2016

---

# Shortcode doesn't work on text widget

 *  Resolved [pegasus81](https://wordpress.org/support/users/pegasus81/)
 * (@pegasus81)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/shortcode-doesnt-work-on-text-widget/)
 * This code doesn’t show anything if added in a text widget:
    [download-attachments
   container=”div” container_id=”327″ title=”” style=”list” display_icon=”1″ display_empty
   =”1″ display_user=”0″] It works only on page specified by id (in this case 327).
   Is it possible to resolve it? Thanks.
 * [https://wordpress.org/plugins/download-attachments/](https://wordpress.org/plugins/download-attachments/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [dFactory](https://wordpress.org/support/users/dfactory/)
 * (@dfactory)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/shortcode-doesnt-work-on-text-widget/#post-5913340)
 * You just have to enable executing shortcodes in text widgets.
 * Google is your best friend here, but this should do the trick:
 * `add_filter('widget_text', 'do_shortcode');`
 * Regards,
    Bartosz / dfactory
 *  Thread Starter [pegasus81](https://wordpress.org/support/users/pegasus81/)
 * (@pegasus81)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/shortcode-doesnt-work-on-text-widget/#post-5913409)
 * I added that code in my theme’s function.php file, but nothing changed. I explain
   better the situation: I created a text widget with this code inside:
    `[download-
   attachments container="div" container_id="327" title="" style="list" display_icon
   ="1" display_empty="1" display_user="0"]` This widget should be visible on more
   pages on the right column, but I can see attachments only if the page has the
   same ID specified in code, otherwise widget shows “No attachments to download”
   Thanks.
 *  Plugin Author [dFactory](https://wordpress.org/support/users/dfactory/)
 * (@dfactory)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/shortcode-doesnt-work-on-text-widget/#post-5913423)
 * Ok, it’s not possible yet.
 * If you’d like to check something, please go to plugin folder/includes/shortcodes.
   php and change the entire download_attachments_shortcode() function into this:
 *     ```
       /**
        * Handles download-attachments shortcode
       */
       public function download_attachments_shortcode($args)
       {
       	$defaults = array(
       		'post_id' => 0,
       		'container' => 'div',
       		'container_class' => 'download-attachments',
       		'container_id' => '',
       		'style' => isset($this->options['general']['display_style']) ? esc_attr($this->options['general']['display_style']) : 'list',
       		'link_before' => '',
       		'link_after' => '',
       		'display_user' => (int)$this->options['general']['frontend_columns']['author'],
       		'display_icon' => (int)$this->options['general']['frontend_columns']['icon'],
       		'display_count' => (int)$this->options['general']['frontend_columns']['downloads'],
       		'display_size' => (int)$this->options['general']['frontend_columns']['size'],
       		'display_date' => (int)$this->options['general']['frontend_columns']['date'],
       		'display_caption' => (int)$this->options['general']['frontend_content']['caption'],
       		'display_description' => (int)$this->options['general']['frontend_content']['description'],
       		'display_empty' => 0,
       		'display_option_none' => __('No attachments to download', 'download-attachments'),
       		'use_desc_for_title' => 0,
       		'exclude' => '',
       		'include' => '',
       		'title' => __('Download Attachments', 'download-attachments'),
       		'orderby' => 'menu_order',
       		'order' => 'asc',
       		'echo' => 1
       	);
   
       	//we have to force return in shortcodes
       	$args['echo'] = 0;
   
       	if(!isset($args['title']))
       	{
       		$args['title'] = '';
   
       		if($this->options['general']['label'] !== '')
       		$args['title'] = $this->options['general']['label'];
       	}
   
       	$args = shortcode_atts($defaults, $args);
   
       	// reassign post id
       	$post_id = (int)(empty($args['post_id']) ? get_the_ID() : $args['post_id']);
   
       	// unset from args
       	unset($args['post_id']);
   
       	return da_display_download_attachments($post_id, $args);
       }
       ```
   
 * Then just pass, for example post_id=”1″ (to get attachments from post of ID 1).
   I’d be greatful for the feedback if that works.
 *  Thread Starter [pegasus81](https://wordpress.org/support/users/pegasus81/)
 * (@pegasus81)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/shortcode-doesnt-work-on-text-widget/#post-5913453)
 * You are the best! Works like a charm!
 *  Plugin Author [dFactory](https://wordpress.org/support/users/dfactory/)
 * (@dfactory)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/shortcode-doesnt-work-on-text-widget/#post-5913455)
 * Happy to hear that 🙂
 * This change will be available in the next DA update, sou you won’t have to modify
   the code.
 * Regards,
    Bartosz / dfactory

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Shortcode doesn't work on text widget’ is closed to new replies.

 * ![](https://ps.w.org/download-attachments/assets/icon-256x256.png?rev=1018456)
 * [Download Attachments](https://wordpress.org/plugins/download-attachments/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/download-attachments/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/download-attachments/)
 * [Active Topics](https://wordpress.org/support/plugin/download-attachments/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/download-attachments/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/download-attachments/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [dFactory](https://wordpress.org/support/users/dfactory/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/shortcode-doesnt-work-on-text-widget/#post-5913455)
 * Status: resolved