Come sovrascrivere le funzioni del tema genitore nei child theme?

23 gen 2011, 15:28:02
Visualizzazioni: 17K
Voti: 31

Ho cercato in giro e provato a capire come fare, ma per qualche motivo non riesco a sovrascrivere le funzioni del tema genitore nel mio child theme.

Sto usando TwentyTen come tema genitore - qualcuno può spiegarmi perché questa funzione nel mio child theme non sovrascrive quella del genitore?

// Sovrascrivi il link "Continua a leggere"
function osu_twentyten_continue_reading_link() {
 return ' <a href="'. get_permalink() . '">' . __( 'Continua a leggere <span class="meta-nav">&rarr;</span>', 'twentyten-child' ) . '</a>';
}
function osu_twentyten_auto_excerpt_more( $more ) {
 return ' &hellip;' . osu_twentyten_continue_reading_link();
}
remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
add_filter( 'excerpt_more', 'osu_twentyten_auto_excerpt_more' );

Pensavo che bisognasse prima rimuovere il filtro/azione ecc. prima di riaggiungerlo, giusto?

Grazie,

osu

0
Tutte le risposte alla domanda 1
1
33

Dovresti eseguire il codice dopo la configurazione del tema.

function osu_twentyten_continue_reading_link() {
    return ' <a href="'. get_permalink() . '">' . __( 'Continua a leggere <span class="meta-nav">&rarr;</span>', 'twentyten-child' ) . '</a>';
}

function osu_twentyten_auto_excerpt_more( $more ) {
    return ' &hellip;' . osu_twentyten_continue_reading_link();
}

function my_child_theme_setup() {
    remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
    add_filter( 'excerpt_more', 'osu_twentyten_auto_excerpt_more' );
}

add_action( 'after_setup_theme', 'my_child_theme_setup' );
23 gen 2011 15:34:42
Commenti

Sì. E il motivo per cui non funziona direttamente è che il codice del child theme viene caricato prima di quello del parent theme.

Rarst Rarst
23 gen 2011 16:37:29