Child Theme functions.php

  • bobsled

    #3680

    I changed the closed comments message in comments.php from ‘Comments have been disabled’ to ‘Comments for this post have are closed’.

    As I just updated to 1.6.1 it obviously over wrote this change durning the upgrade. I was just about to go and change it again, but then wondered if I can make this change by using my child theme’s function.php.

    Is this possible?

    Prasanna SP

    #25515

    Yes, it is possible. Add this to your child theme’s functions.php. (Add php markup if your functions.php file is empty)

    function graphene_filter_gettext( $translated, $original, $domain ) {
    $strings = array(
    'Comments have been disabled' => 'Comments for this post have are closed',
    );
    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 );

    bobsled

    #25516

    Wow, that was fast! Thank you.

    My functions.php is empty. But I don’t understand what you mean by ‘Add php mark up’. Sorry.

    Prasanna SP

    #25517

    Add <?php at the beginning and ?> at the end of the code

    <?php

    function graphene_filter_gettext( $translated, $original, $domain ) {
    $strings = array(
    'Comments have been disabled' => 'Comments for this post have are closed',
    );
    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 );

    ?>

    bobsled

    #25518

    Added this, but no change. Cleared cache etc.

    <?php

    function graphene_filter_gettext( $translated, $original, $domain ) {
    $strings = array(
    'Comments have been disabled' => 'Comments for this post are closed',
    );
    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 );

    ?>

    Prasanna SP

    #25519

    Make sure Comments have been disabled resembles the original string in the parent theme’s comments file.

    Prasanna SP

    #25520

    Also, remove the space in second line. I’ve added that to differentiate my first and second piece of code.

    bobsled

    #25521

    Perfect!! Works like a charm. Thank you :))

    Prasanna SP

    #25522

    🙂 You are welcome!

    Marking thread as resolved.

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

You must be logged in to reply to this topic.