繁体   English   中英

WordPress的主题功能覆盖

[英]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, __( '&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
        }
    }
}

在我的儿童主题中:

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文件中找不到正确的方法来覆盖它。

我试过这种方法:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM