ThemeShaper Forums » Thematic


move code from header file to functions.php

(7 posts)
  • Started 9 years ago by PitaMaria
  • Latest reply from helgatheviking
  • This topic is resolved
  1. PitaMaria

    Apologies if this topic is covered in this forum; I searched but couldn't find anything relevant.

    I'm using the code below to customize page titles, but have only figured out how to make it work placed in my child theme's header.php file. Is it possible to move this code out of that header file and put it in my functions.php? If so, would you be so kind as to provide the syntax that I may copy and paste? Thanks in advance for your attention to this issue.

    	 * Print the <title> tag based on what is being viewed.
    	global $page, $paged;
    	wp_title( '|', true, 'right' );
    	// Add the blog name.
    	bloginfo( 'name' );
    	// Add the blog description for the home/front page.
    	$site_description = get_bloginfo( 'description', 'display' );
    	if ( $site_description && ( is_home() || is_front_page() ) )
    		echo " | $site_description";
    	// Add a page number if necessary:
    	if ( $paged >= 2 || $page >= 2 )
    		echo ' | ' . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) );
    Posted 9 years ago #
  2. Hmm, I know this is going to come up. Are you using a Thematic Child Theme? It would take some serious butchering to work this into a child theme considering all the relevant information for titles is handled in the extensions file. :/

    There is something else going on here, more to fix than just converting this to a functions.php snippet.

    Posted 9 years ago #
  3. PitaMaria

    @ScottNix: Yes, I'm using a Thematic child theme. That snippet is being used successfully in my child theme's header.php file ... I'm just trying to eliminate all child theme files except for style.css and functions.php, and the page-titling automation this snippet provides is the only thing keeping me from doing that.

    Am I understanding you correctly that I could do something to an extensions file in my child theme? What's that?

    Posted 9 years ago #
  4. I think you can create new function name childtheme_override_doctitle() in your functions.php then put your code into that.

    Posted 9 years ago #
  5. this code is automatically added via thematic_doctitle() in the default header.php. so there is no need to manually include it in a child header.php

    Posted 9 years ago #
  6. PitaMaria

    Thanks, gang, for your replies. I was mixing up this issue with another project built on TwentyTen. Re-inserting brain now.

    Posted 9 years ago #
  7. i should reinsert my brain from time to time. that's a neat trick. actually, middlesister has convinced me that this bit of code is "doing it wrong"... in the sense that it is hard-coding things into doc-title that seo plugins then have to bludgeon to get out of there.... or can't at all.

    a better approach might be

    <title><?php wp_title( '|', true, 'right' ); ?></title>

    and then filter in the rest via the wp_title filter that lives inside the wp_title function.

    Posted 9 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.