wordpress主题功能覆盖

时间:2015-08-25 19:39:24

标签: php wordpress

我需要覆盖这个父主题函数:

coming back

在我的孩子主题中有这个:

    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, __( '&laquo; Previous', 'travelify' ) ); ?></li>
                <li class="next"><?php next_image_link( false, __( 'Next &raquo;', 'travelify' ) ); ?></li>
            </ul>
        <?php
        }
        else {
        ?>
            <ul class="default-wp-page clearfix">
                <li class="previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', 'travelify' ) . '</span> %title' ); ?></li>
                <li class="next"><?php next_post_link( '%link', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', 'travelify' ) . '</span>' ); ?></li>
            </ul>
        <?php
        }
    }
}

我无法找到在我的子主题functions.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, __( '&laquo; Previous', 'travelify' ) ); ?></li>
                <li class="next"><?php next_image_link( false, __( 'Next &raquo;', '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中添加什么来替换该特定函数?

1 个答案:

答案 0 :(得分:0)

你可以试试这个

    <?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