【发布时间】:2025-12-30 13:05:09
【问题描述】:
我需要重写这个父主题函数:
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....
}
这只是给了我一个白屏。
我需要在我的子主题 functions.php 中添加什么来替换该特定功能?
【问题讨论】: