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

我想创建一个函数,在我的 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

全部回复(1)
P粉600845163

如果只是为了样式目的,我会使用 css text-transform 来代替。

https://developer.mozilla.org/en -US/docs/Web/CSS/text-transform

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!