Php WordPress:向Yoast SEO面包屑添加页面

Php WordPress:向Yoast SEO面包屑添加页面,php,wordpress,woocommerce,yoast,Php,Wordpress,Woocommerce,Yoast,我想在我的站点的面包屑路径中添加一个额外的页面。 问题是,我正在使用WooCommerce,而面包屑在我的帐户仪表板上无法正常工作。它始终显示以下轨迹: 主页>我的帐户 即使我在“编辑帐户”这样的子页面上。 这些子页面不是真正的页面。它们是同一页面上的端点 应该是这样的: 主页>我的帐户>订单>订单ID 我试图添加一个页面,但无法找到它。 要从面包屑痕迹中删除页面,我将使用以下代码: /** * Conditionally Override Yoast SEO Breadcrumb Trail

我想在我的站点的面包屑路径中添加一个额外的页面。 问题是,我正在使用WooCommerce,而面包屑在我的帐户仪表板上无法正常工作。它始终显示以下轨迹:

主页>我的帐户

即使我在“编辑帐户”这样的子页面上。 这些子页面不是真正的页面。它们是同一页面上的端点

应该是这样的:

主页>我的帐户>订单>订单ID

我试图添加一个页面,但无法找到它。 要从面包屑痕迹中删除页面,我将使用以下代码:

/**
 * Conditionally Override Yoast SEO Breadcrumb Trail
 * http://plugins.svn.wordpress.org/wordpress-seo/trunk/frontend/class-breadcrumbs.php
 * -----------------------------------------------------------------------------------
 */

add_filter( 'wpseo_breadcrumb_links', 'wpse_100012_override_yoast_breadcrumb_trail' );

function wpse_100012_override_yoast_breadcrumb_trail( $links ) {
    global $post;

    if ( is_home() || is_singular( 'post' ) || is_archive() ) {
        $breadcrumb[] = array(
            'url' => get_permalink( get_option( 'page_for_posts' ) ),
            'text' => 'Blog',
        );

        array_splice( $links, 1, -2, $breadcrumb );
    }

    return $links;
}
代码来自此处: 我已经更改了它,以检查我是否在WooCommerce端点上

这段代码运行良好。 但是我如何才能将其更改为添加页面而不是删除页面

我猜这与
阵列拼接有关

好的,我有一个解决办法

非常感谢@WebElaine的回答:

以下是我在我的帐户区域更改Yoast面包屑导航的完整代码:

add_filter('wpseo_breadcrumb_links', 'woocommerce_account_breadcrumb_trail');
function woocommerce_account_breadcrumb_trail($links) {
    if ( is_wc_endpoint_url() or is_account_page() ) {

        $endpoint       = WC()->query->get_current_endpoint();
        $endpoint_title = WC()->query->get_endpoint_title( $endpoint );
        $endpoint_url   = wc_get_endpoint_url($endpoint);

        if ( is_account_page() && !is_wc_endpoint_url() ) :
            //$links[2] = array('text' => $endpoint_title, 'url' => $endpoint_url, 'allow_html' => 1);

        elseif ( is_wc_endpoint_url( 'edit-account' ) ) :
            $links[2] = array('text' => $endpoint_title, 'url' => $endpoint_url, 'allow_html' => 1);

        elseif ( is_wc_endpoint_url( 'orders' ) ) :
            $links[2] = array('text' => $endpoint_title, 'url' => $endpoint_url, 'allow_html' => 1);

            elseif ( is_wc_endpoint_url( 'view-order' ) ) :
                $endpoint_orders        = 'orders';
                $endpoint_orders_title  = WC()->query->get_endpoint_title( $endpoint_orders );
                $endpoint_orders_url    = wc_get_endpoint_url($endpoint_orders);

                $links[2] = array('text' => $endpoint_orders_title, 'url' => $endpoint_orders_url, 'allow_html' => 1);
                $links[3] = array('text' => $endpoint_title, 'url' => $endpoint_url, 'allow_html' => 1);

        elseif ( is_wc_endpoint_url( 'edit-address' ) ) :
            $links[2] = array('text' => $endpoint_title, 'url' => $endpoint_url, 'allow_html' => 1);

        elseif ( is_wc_endpoint_url( 'payment-methods' ) ) :
            $links[2] = array('text' => $endpoint_title, 'url' => $endpoint_url, 'allow_html' => 1);

            elseif ( is_wc_endpoint_url( 'add-payment-method' ) ) :
                $endpoint_payment_methods       = 'payment-methods';
                $endpoint_payment_methods_title = WC()->query->get_endpoint_title( $endpoint_payment_methods );
                $endpoint_payment_methods_url   = wc_get_endpoint_url($endpoint_payment_methods);

                $links[2] = array('text' => $endpoint_payment_methods_title, 'url' => $endpoint_payment_methods_url, 'allow_html' => 1);
                $links[3] = array('text' => $endpoint_title, 'url' => $endpoint_url, 'allow_html' => 1);

        endif;

    }

    return $links;

}
我对每一个反馈都很满意