WordPress.org

Ready to get started?Download WordPress

Forums

Twenty Twelve
[resolved] Overriding twentytwelve_wp_title in a child theme (5 posts)

  1. eVolts
    Member
    Posted 1 year ago #

    Hello,

    I'm trying to override the twentytwelve_wp_title function in a child theme to remove the site description and use a different separator, but it's not possible.
    How can I do this without using a modified header.php?
    May the twentytwelve_wp_title function be pluggable in a future version?
    Thanks!

    eV

    http://wordpress.org/extend/themes/twentytwelve/

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    no need for the function to be pluggable, as it is added as a filter function;
    see: add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );

    remove it from the filter, and add your own function.

  3. eVolts
    Member
    Posted 1 year ago #

    Hi alchymyth,

    thanks for your answer!
    So I've to remove it from inside myown_wp_title function? Because I can't remove it from my functions.php file, since is loaded before the parent one.
    This a overhead of add and remove of functions, isn't it?

    Bye,
    eV

  4. alchymyth
    Forum Moderator
    Posted 1 year ago #

    this for example works for me, in a child theme of Twenty Twelve:

    add_action('after_setup_theme','adjust_twentytwelvechild_wp_title');
    
    function adjust_twentytwelvechild_wp_title() {
    	remove_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );
    	add_filter( 'wp_title', 'twentytwelvechild_wp_title', 10, 2 );
    }
    
    function twentytwelvechild_wp_title( $title, $sep ) {
    	global $paged, $page;
    /*your wp_title code here*/
    	return $title;
    }
  5. eVolts
    Member
    Posted 1 year ago #

    Thanks alchymyth, I'll go this way.

    Just for the records, I still think this is an overhead of function calling, that can be avoided just making the twentytwelve_wp_title function pluggable.

    Bye,
    eV

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic