Support » Plugins » After adding Widget in theme, getting warning

  • Resolved shikhadas


    I am creating a theme and after adding a widget file to the theme, i am getting the below error.

    Warning: Cannot modify header information - headers already sent by (output started at C:\xampplite\htdocs\director\wp-content\themes\Director\director-widgets.php:71) in C:\xampplite\htdocs\director\wp-includes\pluggable.php on line 876

    My widget file is below –

    class Director_Featured_Widget extends WP_Widget {
    	public function __construct() {
    	 		'director_featured_business', // Base ID
    			'Featured Business', // Name
    			array( 'description' => __( 'Displays the Featured Business')) // Args
    	public function update( $new_instance, $old_instance ) {
    		$instance = array();
    		$instance['title'] = strip_tags( $new_instance['title'] );
    		return $instance;
    	public function form( $instance ) {
    		$title = (isset( $instance[ 'title' ])) ? $instance[ 'title' ] : 'Featured Business';
    		<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
    		<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
    	public function widget( $args, $instance ) {
    		extract( $args );
    		$title = apply_filters( 'widget_title', $instance['title'] );
    		echo $before_widget;
    		if ( ! empty( $title ) ) echo $before_title . $title . $after_title;
    		$args= array(
    			'post_type' => 'businesses',
    			'posts_per_page' => 1,
    			'tax_query' => array(
    						'taxonomy' => 'business-type',
    						'field' => 'slug',
    						'terms' => 'featured'
    	$featuredWidget= new WP_Query($args);
    	while ( $featuredWidget->have_posts() ) : $featuredWidget->the_post(); ?>
    	<div class="widget_featured">
    		<div class="thumb"><?php print get_the_post_thumbnail($post->ID); ?></div>
    		<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    		<?php the_excerpt(); ?>
    		echo $after_widget;
    register_widget( 'Director_Featured_Widget' );

    and i am adding below line in function.php to call it


    I am not finding any solution anywhere and a temporary solution is to add below in wp-config.php which i don’t want to use as i have to submit it to wordpress and can’t ask users of theme to do so.


    Please help me as this is my first theme.

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi


    Forum Moderator

    Are you using this theme:

    Nope..mine is a different theme. I myself created it using whiteboard framework. I still have not submitted it.

    Everything went well, till adding of the widget file director-widgets.php



    Forum Moderator

    All I can suggest is that you try reviewing Solving “headers already sent” warnings.

    Thanks for the suggestion. My theme is working fine after i did this in my director-widgets.php

    Place the cursor between the ? and >
    Now press the DELETE key on your computer
    Note to MAC users: The "DELETE" key on a PC deletes characters to the right of the cursor. That is the key noted here.
    Keep that key pressed
    For at least 15 seconds
    Now type > and
    save without pressing any other key at all.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘After adding Widget in theme, getting warning’ is closed to new replies.