首页 > 解决方案 > 在 function.php 文件中获取产品标题

问题描述

我正在尝试在 functions.php 页面上获取当前的 woocommerce 产品标题。我尝试使用 $product->ID、get_the_title 等所有功能,但没有人在工作。

function custom_title() {
    global $new_myKey, $post, $product;

    $cache_key = 'myKey';
    $myKey = wp_cache_get( $cache_key );
    if( false === $myKey ){
         $new_myKey = get_the_title();
        wp_cache_set( $myKey, $new_myKey );
    }

}
add_action( 'after_setup_theme', 'custom_title' );

此时 $new_myKey = get_the_title(); 我想获得动态产品标题。有什么办法吗?

感谢和问候在此处输入图像描述

标签: phpwordpresswoocommerce

解决方案


推荐阅读