ERROR warning after adding the following codes to my child .php file

  • needhelp101

    #6415

    Adding the following codes to a child theme .php file is giving an ERROR WARNING that there is an error in line 749, 750,751,752….. I have checked for spaces at the <?php and ?> and there is no space.

    ThiS code to add date to my top bar

    <?php function graphene_top_bar_date() {
    echo '<p id="top-bar-date">'.date('l, F j, Y').'</p>';
    }
    add_action('graphene_top_bar','graphene_top_bar_date'); ?>

    AND THis code below to REMOVE the word ARCHIVE from my category title

    <?php function graphene_filter_gettext( $translated, $original, $domain ) {
    $strings = array(
    'Category Archive: <span>%s</span>' => '<span>%s</span>',
    );
    if ( ! empty( $strings[$original] ) ) {
    $translations = &get_translations_for_domain( $domain );
    $translated = $translations->translate( $strings[$original] );
    }
    return $translated;
    }
    add_filter( 'gettext', 'graphene_filter_gettext', 10, 3 );?>
    Admin

    Syahir Hakim

    #33053

    What’s the exact error message?

    needhelp101

    #33054

    One of them goes like this

    Warning: Cannot modify header information – headers already sent by (output started at /home/content/49/10146549/html/wp-content/themes/Graphene-Child/functions.php:13) in /home/content

    Prasanna SP

    #33055

    Try this

    <?php
    function graphene_top_bar_date() {
    echo '<p id="top-bar-date">'.date('l, F j, Y').'</p>';
    }
    add_action('graphene_top_bar','graphene_top_bar_date');

    function graphene_filter_gettext( $translated, $original, $domain ) {
    $strings = array(
    'Category Archive: <span>%s</span>' => '<span>%s</span>',
    );
    if ( ! empty( $strings[$original] ) ) {
    $translations = &get_translations_for_domain( $domain );
    $translated = $translations->translate( $strings[$original] );
    }
    return $translated;
    }
    add_filter( 'gettext', 'graphene_filter_gettext', 10, 3 );
    ?>

    Put code in between backtick (

    Code:
    `

    ) characters. It’s usually located above the Tab key on your keyboard.

    needhelp101

    #33056

    Thanks for your speedy response. I will put this code in my functions.php, give it an hour and check back. By the way when you make your child .php file do you need to put anything else at the beginning or you just start to add your code between <?php and ?>. And as I can see from your response I maybe just need a single <?php and ?> and then I just put all my modifications there instead of having a <?php and ?> for each code.

    Again thanks much for the speedy response

    Mod

    Kenneth John Odle

    #33057
    Quote:
    do you need to put anything else at the beginning or you just start to add your code between <?php and ?>.

    No. The “headers already sent” error is usually an indication that you have a stray space before the opening php tag or after the closing php tag.

    Quote:
    I maybe just need a single <?php and ?> and then I just put all my modifications there instead of having a <?php and ?> for each code.

    That is the way it is usually done, and it works fine. It makes it easier to keep track of things, as well.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.