ThemeShaper Forums » Thematic

[closed]

Overriding filters in child themes

(3 posts)
  • Started 8 years ago by jcollier
  • Latest reply from jcollier
  • This topic is not resolved
  1. I would like to add content above page posttitles in my child theme.

    I've been able to do an amazing amount of Thematic customization already -- for example, I understand how to remove and add functions -- however I haven't been able to find clear instructions for overriding filters in child themes.

    I found the // Create post title filter code in content-extensions.php, and this is what I came up with. I only added the bcn if/else statement.

    However, I'm *clearly* not fluent in PHP, so I created a white screen of death.

    Is there anyone who can let me know if I'm moving in the right direction or not?

    // Replace post title
    
    add_action('init', 'remove_postheader_posttitle');
    
    function my_thematic_postheader_posttitle($posttitle) {
    
        if (is_single() || is_page()) {
            if(function_exists('bcn_display')){
              $posttitle = '<div class="breadcrumb">';
              $posttitle .= bcn_display();
              $posttitle .= '</div>';
              $posttitle .= '<h1 class="entry-title">' . get_the_title() . "</h1>\n";
            } else {
              $posttitle = '<h1 class="entry-title">' . get_the_title() . "</h1>\n";
            }
        } elseif (is_404()) {
            $posttitle = '<h1 class="entry-title">' . __('Not Found', 'thematic') . "</h1>\n";
        } else {
            $posttitle = '<h2 class="entry-title"><a href="';
            $posttitle .= get_permalink();
            $posttitle .= '" title="';
            $posttitle .= __('Permalink to ', 'thematic') . the_title_attribute('echo=0');
            $posttitle .= '" rel="bookmark">';
            $posttitle .= get_the_title();
            $posttitle .= "</a></h2>\n";
            return $posttitle;
        }
    	add_filter('thematic_postheader_posttitle', 'my_postheader_posttitle');
    
    } // end Replace thematic_postheader_posttitle
    Posted 8 years ago #
  2. function my_postheader_posttitle($posttitle) {
    
        if (is_single() || is_page()) {
            if(function_exists('bcn_display')){
              $posttitle = '<div class="breadcrumb">';
              $posttitle .= bcn_display();
              $posttitle .= '</div>';
              $posttitle .= '<h1 class="entry-title">' . get_the_title() . "</h1>\n";
            } else {
              $posttitle = '<h1 class="entry-title">' . get_the_title() . "</h1>\n";
            }
        } elseif (is_404()) {
            $posttitle = '<h1 class="entry-title">' . __('Not Found', 'thematic') . "</h1>\n";
        } else {
            $posttitle = '<h2 class="entry-title"><a href="';
            $posttitle .= get_permalink();
            $posttitle .= '" title="';
            $posttitle .= __('Permalink to ', 'thematic') . the_title_attribute('echo=0');
            $posttitle .= '" rel="bookmark">';
            $posttitle .= get_the_title();
            $posttitle .= "</a></h2>\n";
    
        }
    		return $posttitle;
    }
    add_filter('thematic_postheader_posttitle', 'my_postheader_posttitle');

    filters basically work like this:

    function my_version($filtered_variable) {
       $filtered_variable = "Bacon!";
       return $filtered_variable;
    
    }
    add_filter('thematic_function_to_be_filtered','my_version');

    passing the $filtered_variable as a parameter in my_version() is optional depending on if you want/need to import the original values. for instance, the original post title is generated and you want to tack "bacon" on to the end (versus overwriting the entire thing) then you would do:

    $filtered_variable .= "Bacon!";

    and just before the function ends you need to return the $filtered_variable. then you call the add_filter function.

    Posted 8 years ago #
  3. Thank you!

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.