Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WooCommerce类别页面上的自定义页面标题和说明_Php_Wordpress_Advanced Custom Fields - Fatal编程技术网

Php WooCommerce类别页面上的自定义页面标题和说明

Php WooCommerce类别页面上的自定义页面标题和说明,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我使用高级自定义字段在我的所有页面、帖子、类别和产品上添加自定义页面标题字段 为了删除默认的标记并确保该字段正确通过,我在functions.php文件中使用了以下函数: /* Remove Default <title> tag */ remove_action( 'wp_head', '_wp_render_title_tag', 1 ); // Add new <title> and description tags function child_them

我使用高级自定义字段在我的所有页面、帖子、类别和产品上添加自定义页面标题字段

为了删除默认的
标记并确保该字段正确通过,我在functions.php文件中使用了以下函数:

/* Remove Default <title> tag */

remove_action( 'wp_head', '_wp_render_title_tag', 1 );


// Add new <title> and description tags 

function child_theme_head_script() { ?>
  <title><?php the_field('seo_page_title'); ?></title>
  <meta name="description" content="<?php the_field('seo_page_description'); ?>"/>
  <!-- Your HTML goes here -->
<?php }
add_action( 'wp_head', 'child_theme_head_script' );
_field()
只能在循环中使用,这就是为什么它在从当前循环项中提取数据时会这样做。如果要以分类法的字段为目标,则需要将对该分类法的引用传递给函数

我建议这样做:

$term = get_queried_object();
the_field('seo_page_title', $term);
以下是ACF文档中的相关页面:

_字段()
只能在循环中使用,这就是为什么它这样做是因为它从当前循环项中提取数据。如果要以分类法的字段为目标,则需要将对该分类法的引用传递给函数

我建议这样做:

$term = get_queried_object();
the_field('seo_page_title', $term);

下面是ACF文档中的相关页面:

非常感谢,Peter,我想我理解了-我在页面上显示它们时也曾尝试过类似的方法,但由于这是在函数文件中,我不确定语法是否正确。。。我已经根据你的建议更新了我的问题,但这似乎没有影响任何事情。。。另外,如果这真的有效,这对正常页面是否仍然有效?或者我必须同时使用原始代码和新代码吗?我实际上认为我可能通过在实际函数内部而不是外部添加术语信息来实现它!将很快更新…这似乎根据您的建议起作用-可以将其添加到您的答案中:)/*删除默认标记*/删除操作('wp\u head','wp\u render\u title\u tag',1);函数子主题头脚本(){?>非常感谢,Peter,我想我明白了-我在页面上显示它们的时候也遇到过类似的情况,但是由于这是在函数文件中,我不确定语法是否正确…我已经用我根据您的建议尝试过的一些东西更新了我的问题,但这似乎不会影响任何事情…而且如果这确实有效,我不会他仍然适用于普通页面?或者我必须同时使用原始代码和新代码吗?我实际上认为我可能已经通过在实际函数中而不是在函数外部添加术语信息来工作了!很快将更新…这似乎根据您的建议起作用-请随意将其添加到您的答案中:)/*删除默认标记*/移除动作('wp\u head','wp\u render\u title\u tag',1);函数子项\u主题\u head\u脚本(){?>