[英]wordpress theme function override
我需要重寫此父主題函數:
add_action( 'travelify_after_post_content', 'travelify_next_previous_post_link', 10 );
/**
* Shows the next or previous posts link with respective names.
*/
function travelify_next_previous_post_link() {
if ( is_single() ) {
if( is_attachment() ) {
?>
<ul class="default-wp-page clearfix">
<li class="previous"><?php previous_image_link( false, __( '« Previous', 'travelify' ) ); ?></li>
<li class="next"><?php next_image_link( false, __( 'Next »', 'travelify' ) ); ?></li>
</ul>
<?php
}
else {
?>
<ul class="default-wp-page clearfix">
<li class="previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'travelify' ) . '</span> %title' ); ?></li>
<li class="next"><?php next_post_link( '%link', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'travelify' ) . '</span>' ); ?></li>
</ul>
<?php
}
}
}
在我的兒童主題中:
add_action( 'travelify_after_post_content', 'travelify_next_previous_post_link', 10 );
/**
* Shows the next or previous posts link with respective names.
*/
function travelify_next_previous_post_link() {
if ( is_single() ) {
if( is_attachment() ) {
?>
<ul class="default-wp-page clearfix">
<li class="previous"><?php previous_image_link( false, __( '« Previous', 'travelify' ) ); ?></li>
<li class="next"><?php next_image_link( false, __( 'Next »', 'travelify' ) ); ?></li>
</ul>
<?php
}
else {
?>
<ul class="default-wp-page clearfix">
<li class="previous"><?php previous_post_link_plus( array('order_by' => 'menu_order', 'loop' => true, 'link' => '%title' ) ); ?></li>
<li class="next"><?php next_post_link_plus( array('order_by' => 'menu_order', 'loop' => true, 'link' => '%title' ) ); ?></li>
</ul>
<?php
}
}
}
我在我的子主題functions.php文件中找不到正確的方法來覆蓋它。
我試過這種方法:
if ( ! function_exists( 'travelify_next_previous_post_link' ) )
function travelify_next_previous_post_link() {
NEW FUNCTION HERE....
}
那只是給我一個白屏。
我需要在子主題函數中放入什么以替換該特定函數?
你可以試試這個
<?php
function child_remove_parent_function() {
remove_action( 'travelify_after_post_content', 'travelify_next_previous_post_link', 10 );
}
add_action( 'wp_loaded', 'child_remove_parent_function' );
?>
刪除要加載的功能。
或者,您可以增加子功能的優先級。這是您的完整解決方案。 http://code.tutsplus.com/tutorials/a-guide-to-overriding-parent-theme-functions-in-your-child-theme--cms-22623
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.