通过将帖子和页面的标题 (h1 - h6) 大写来增强 WordPress
P粉023326773
P粉023326773 2023-09-09 11:08:11
0
1
341

我想创建一个函数,在我的 WordPress 网站的标题中将大写(每个单词的第一个字母都大写)。

我已经能够开发一个用于过滤的正则表达式 preg_match_all()。

问题是如何迭代匹配项并使用 ucwords() 函数将标题大写。最后,将大写标题插入到内容中。

我尝试了这段代码。问题是if (is_array())

之后如何进行
function headings_in_the_content($content)
{
    $regexpattern = '#(?P<full_tag><(?P<tag_name>h\d)(?P<tag_extra>[^>]*)>(?P<tag_contents>[^<]*)</h\d>)#i';
    if (preg_match_all($regexpattern, $content, $matches)) {
        foreach ($matches as $regexmatches) {
            
             if (is_array($regexmatches)) {
                    foreach ($regexmatches as $regexmatch)
                        {

                        }
            }

        }
        
    }

    return $content;
}

add_filter('the_content', 'headings_in_the_content', 15000);

P粉023326773
P粉023326773

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!