• Resolved idacma

    (@idacma)


    I am having trouble with my child theme, I cannot log inn, there is just a blank page and have to change the theme to a default theme in order to have access to the wordpress dashboard. The error: PHP Warning: Cannot modify header information – headers already sent by (output started at /home2/ssalonge/public_html/wp-content/themes/twentyseventeen-child/functions.php:1)in /home2/ssalonge/public_html/wp-includes/pluggable.php on line 1268

    Apparently the file is missing or something, but the webpage is working fine when going to the page. I just need the wordpress dashboard to work.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Look in your wp-content/themes/twentyseventeen-child/functions.php file on line 1 and make sure there is no white space before the <?php tag. The tag needs to be the very first thing in the file. If it looks like it is the first thing, you could be using an editor that adds the Byte Order Mark (BOM) which is invisible but first.

    Thread Starter idacma

    (@idacma)

    Thank you, will try this right away, there was actually a lot of white space!

    Thread Starter idacma

    (@idacma)

    Ok so that did not seem to work, my functions file looks like this (sorry about the comments being in a different language):

    <?php
        add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
        
    	function enqueue_parent_styles() {
           wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' 
    	);
        }
        ?>
    
    <?php /*?>for å få bort "posts på fremside"<?php */ ?>
    <?php add_filter( 'gettext', 'change_front_page_title', 20, 3 );
    
    function change_front_page_title( $translated_text, $text, $domain ) {
    
    if (is_front_page()){
    
                switch ( $translated_text ) {
    
            case 'Posts' :
    
                $translated_text = __( 'Kommende utstillinger', 'twentyseventeen' );
                break;
        }
    }
    return $translated_text;
    }?>
    
    <?php /*?>Ikke få hele posten på fremside<?php */?>
    <?php function catch_that_image() {
      global $post, $posts;
      $first_img = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_img = $matches [1] [0];
     
      if(empty($first_img)){ //Defines a default image
        $first_img = "/images/default.jpg";
      }
      return $first_img;
    }
    ?>
    • This reply was modified 5 years, 6 months ago by idacma.
    Thread Starter idacma

    (@idacma)

    ok never mind I was too quick in saying it did not work, I was able to get it fixed by removing all white space before all <?php and after all ?>. Thank you so much for your help! 😀

    • This reply was modified 5 years, 6 months ago by idacma.

    I’m glad you got it cleaned up, but the functions.php file is not a template, so it should be mostly PHP, and so it should have one <?php tag at the top and that is it (only close it if exact HTML is being output in a function). Remove the ?> tags, even the one at the end of the file.

    This line is especially crazy:
    <?php /*?>for å få bort "posts på fremside"<?php */ ?>
    It seems like it would be outputting that sentence…

    In the catch_that_image function, what is the point of this?

      ob_start();
      ob_end_clean();
    Thread Starter idacma

    (@idacma)

    <?php /*?>for å få bort "posts på fremside"<?php */ ?> is just a comment so I know what the code is for, I really do not understand php so I have just copy pasted codes so cannot say what everything is for unfortunately, but trying to pick up as much as I can. Thank you for the info, will try and see if I can sort out the php file a little 🙂

    The thing to know about PHP is that it is a filter. When the server loads a PHP file, it parses the content, immediately outputting anything that is not in a <?php ?> tag. For the parts that are <?php tags, it is executed right then.
    This means that since the functions.php file is not a template file (no output is intended), there should be one <?php tag at the top and no others (the content should all be PHP code) unless there is a function that is specifically for some output and might have HTML.

    The code I questioned, using ob_start(), is for output buffering, and it starts it and immediately ends it. So all it does is slow things down. The image is found directly from the post content variable.

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

The topic ‘Child theme log inn error’ is closed to new replies.