Cómo sobrescribir funciones del tema padre en temas hijos

23 ene 2011, 15:28:02
Vistas: 17K
Votos: 31

He estado investigando y tratando de entender cómo hacer esto, pero por alguna razón no logro sobrescribir las funciones del tema padre en mi tema hijo.

Estoy usando TwentyTen como tema padre - ¿alguien puede decirme por qué esta función en mi tema hijo no está sobrescribiendo la función del padre?

// Sobrescribir el enlace "Leer más"
function osu_twentyten_continue_reading_link() {
 return ' <a href="'. get_permalink() . '">' . __( 'Continuar leyendo <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' );

¿No se supone que hay que eliminar el filtro/acción antes de volver a agregarlo, verdad?

Gracias,

osu

0
Todas las respuestas a la pregunta 1
1
33

Debes ejecutar el código después de la configuración del tema.

function osu_twentyten_continue_reading_link() {
    return ' <a href="'. get_permalink() . '">' . __( 'Leer más <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 ene 2011 15:34:42
Comentarios

Sí. Y la razón por la que no funciona directamente es que el código del tema hijo se carga antes que el del tema padre.

Rarst Rarst
23 ene 2011 16:37:29