WordPress短码显示页面标题&排除特定单词形式的标题

发布于 2025-01-26 19:46:10 字数 354 浏览 3 评论 0原文

我有一个显示页面标题的WordPress快捷代码,但是我现在需要排除特定单词形式的页面标题

,有时我在标题单词中有 best或top

例如,如果页面标题是加利福尼亚最佳城市 短码需要显示(加利福尼亚州的 City

这是我有关如何显示标题

function post_title_shortcode(){
    return get_the_title();
}
add_shortcode('page_title','post_title_shortcode');

谢谢的代码

I have a WordPress Shortcode that displays the page title, but I need now to exclude specific words form the Page Title

For example, sometimes I have in the title words like Best or Top

For example, if the page title is Best City in California
shortcode needs to show ( City in California )

This is my code on how to display the title

function post_title_shortcode(){
    return get_the_title();
}
add_shortcode('page_title','post_title_shortcode');

Thank You

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷爱 2025-02-02 19:46:10

似乎很容易。在功能中,post_title_shortcode做类似的事情:

function post_title_shortcode() {
    $replacement = [
        'Bay' => '',
        // add as many as you want
    ];

    return str_replace(
        array_keys($replacement),
        array_values($replacement),
        get_the_title()
    );
}

It seems easy. Inside the function post_title_shortcode do something similar:

function post_title_shortcode() {
    $replacement = [
        'Bay' => '',
        // add as many as you want
    ];

    return str_replace(
        array_keys($replacement),
        array_values($replacement),
        get_the_title()
    );
}
薆情海 2025-02-02 19:46:10

在短码处理程序中写入一些代码以调整标题的文本。这种事情可能有效。

function post_title_shortcode(){
    $title = get_the_title();
    $title = trim( str_replace( 'Best ', '', $title, 1 ) );
    $title = trim( str_replace( 'Top ', '', $title, 1 ) );
    return $title;
}
add_shortcode('page_title','post_title_shortcode');

Write some code in your shortcode handler to adjust the text of the title. This kind of thing might work.

function post_title_shortcode(){
    $title = get_the_title();
    $title = trim( str_replace( 'Best ', '', $title, 1 ) );
    $title = trim( str_replace( 'Top ', '', $title, 1 ) );
    return $title;
}
add_shortcode('page_title','post_title_shortcode');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文