• I am a PHP novice and have managed to do some basic customization using functions.php without breaking anything, but I feel like I’m missing something. Would someone be so kind as to tell me if there is a better way to approach this situation so I can better understand how to apply it to other filters?

    I wanted to change the 404 page header from “Ooops” to “Oops”. The following function in functions.php of my child theme:

    add_filter('tc_404_header_content', 'tc_404_new');
    function tc_404_new(){
    echo '<header class="entry-header">
    <h1 class="entry-title">Oops, page not found</h1>
    <hr class="featurette-divider __before_content">
    </header>';
    }

    correctly replaces the below text generated in class-content-headings.php. I have archive icons disabled.

    ‘if ( is_404() ) {
    $header_class = ‘entry-header’;
    $content = sprintf(‘<h1 class=”entry-title %1$s”>%2$s</h1>’,
    apply_filters( ‘tc_archive_icon’, ” ),
    apply_filters( ‘tc_404_title’ , __( ‘Ooops, page not found’ , ‘customizr’ ) )
    );
    $content = apply_filters( ‘tc_404_header_content’, $content );
    }’

    The reason I think I did something wrong is I had to manually type oout the HTML code for the header tags and <hr> featurette-divider tag, which were previously automatically generated. I think maybe I don’t fully understand the role of the second parameter in apply_filters. What does ,'customizr') mean in this context? Is it a defined variable somewhere?

    Is there another, better way to make this sort of change in functions.php?

    Thanks for any insights!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Try adding this to your child theme functions.php:

    add_filter('tc_archives_headings', 'rdc_archives_headings');
    function rdc_archives_headings($output) {
        return preg_replace('|Ooops|', 'Oops', $output);
    }
    Thread Starter loudnotes

    (@loudnotes)

    Neat trick, thanks! I knew there had to be a better way.

    For future reference though, if I’m replacing more than just a letter, what is the role of ‘customizr’ in assigning formatting? How would I call tc_404_title or tc_archive_icon or other functions from within functions.php?

    The best way is to continue reading the Customizr site and this forum, to get confident with Customizr and php. In the meantime, use the Say What? plugin to change any string to any other (tip: the “domain” in the Say What? settings is customizr).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘functions.php – am I doing it right?’ is closed to new replies.