WordPress.org

Ready to get started?Download WordPress

Forums

Child Theme functions.php "Cannot modify header" error (2 posts)

  1. dasickle
    Member
    Posted 1 year ago #

    Hi,

    I have a child theme with a functions.php that I use to change some of the wp functionality. Everything was working fine until I added the follow code to the file

    <?php
    /**
    * No Feeds
    */
    function disable_feed() {
    wp_redirect( home_url() );
    exit;
    }
    
    add_action('do_feed', 'disable_feed', 1);
    add_action('do_feed_rdf', 'disable_feed', 1);
    add_action('do_feed_rss', 'disable_feed', 1);
    add_action('do_feed_rss2', 'disable_feed', 1);
    add_action('do_feed_atom', 'disable_feed', 1);
    
    function removeHeadLinks() {
          remove_action( ‘wp_head’, ‘feed_links_extra’, 3 );
          remove_action( ‘wp_head’, ‘feed_links’, 2 );
          remove_action( ‘wp_head’, ‘rsd_link’ );
    }
    add_action('init', 'removeHeadLinks');
    ?> 
    
    <?php
    function disable_category_tag_feed () {
     return;
     }
     add_filter('category_feed_link', 'disable_category_tag_feed');
    ?>

    The code above prevents me from accessing /wp-admin and give me the following error: "Warning: Cannot modify header information - headers already sent by (output started at /home/arseniy/public_html/wp-content/themes/businesspro_child/functions.php:13) in /home/arseniy/public_html/wp-includes/pluggable.php on line 876"

    What can I do?

  2. Can you try and remove the ?> and <?php except for the first one?

    So change this to:

    <?php
    /**
    * No Feeds
    */
    function disable_feed() {
    wp_redirect( home_url() );
    exit;
    }
    
    add_action('do_feed', 'disable_feed', 1);
    add_action('do_feed_rdf', 'disable_feed', 1);
    add_action('do_feed_rss', 'disable_feed', 1);
    add_action('do_feed_rss2', 'disable_feed', 1);
    add_action('do_feed_atom', 'disable_feed', 1);
    
    function removeHeadLinks() {
          remove_action( ‘wp_head’, ‘feed_links_extra’, 3 );
          remove_action( ‘wp_head’, ‘feed_links’, 2 );
          remove_action( ‘wp_head’, ‘rsd_link’ );
    }
    add_action('init', 'removeHeadLinks');
    
    function disable_category_tag_feed () {
     return;
     }
     add_filter('category_feed_link', 'disable_category_tag_feed');

Topic Closed

This topic has been closed to new replies.

About this Topic