如何创建一个过滤器挂钩,将改变WordPress中的页面标题

2uluyalo  于 2022-12-11  发布在  WordPress
关注(0)|答案(1)|浏览(117)

我尝试编写一个过滤器,将页面标题从h5更改为h1。下面是我尝试更改的父主题函数的摘录:

function constico_site_breadcrumbs() {

$breadcrumbs_settings = apply_filters( 'constico_breadcrumbs_settings', array(
    'wrapper_format'    => '<div class="container"><div class="row">%1$s<div class="breadcrumbs__items">%2$s</div></div></div>',
    'page_title_format' => '<div class="breadcrumbs__title"><h5 class="page-title">%s</h5></div>',// trying to change this into h1
    'separator'         => '&#47;',
    'show_title'        => $breadcrumbs_page_title,
    'path_type'         => $breadcrumbs_path_type,

我尝试将整个函数复制到带有更改的过滤器挂钩中,但它产生了错误。
function tt_seopagetitle() { // function with changes } add_filter('constico_breadcrumbs_settings','tt_seopagetitle');指导将非常感谢!

2admgd59

2admgd591#

您可以像这样只覆盖page_title_format

function tt_seopagetitle($title){
    $title['page_title_format'] = '<div class="breadcrumbs__title"><h1 class="page-title">%s</h1></div>';
    return $title;
}

add_filter('constico_breadcrumbs_settings', 'tt_seopagetitle', 10)

相关问题