如何在简码中修改页面标题?
如何修改短代码中特定页面的页面标题?
How do I modify a page title for specific pages in shortcode?
以下将更改标题,但它会针对每个页面执行.我需要更多地控制它的执行位置.
The following will change the title but it executes for every page. I need more control over where it executes.
function assignPageTitle(){
return "Title goes here";
}
add_filter('wp_title', 'assignPageTitle');
有没有办法在短代码函数中调用上述内容?我知道如何使用 do_shortcode() 但上面是一个过滤器.
Is there a way to call the above in a shortcode function? I know how to use do_shortcode() but the above is a filter.
我的目标是根据 URL 参数修改页面标题.这只发生在特定页面上.
My goal is to modify the page title based on a URL parameter. This only happens for specific pages.
WordPress 2.5 中引入了 Shortcode API,这是一组简单的用于创建用于发布内容的宏代码的函数.
Introduced in WordPress 2.5 is the Shortcode API, a simple set of functions for creating macro codes for use in post content.
这表明您无法使用短代码控制页面标题,因为短代码在帖子内容中运行,此时标题标签已经呈现,但为时已晚.
This would suggest that you can't control page titles using shortcodes as the shortcode is run inside the post content at which point the title tag has already been rendered and is then too late.
你到底想做什么?使用 Yoast SEO 插件,您可以在每个帖子中设置帖子和页面标题,如果这是您想要的做什么?
What is it exactly that you want to do? Using the Yoast SEO Plugin you can set Post and Page titles within each post if this is what you want to do?
您可以根据您的 URL 参数创建您的自定义插件,如下所示:
You could create your custom plugin based on your URL parameters as so:
function assignPageTitle(){
if( $_GET['query'] == 'something' ) { return 'something'; }
elseif( $_GET['query'] == 'something-else' ) { return 'something-else'; }
else { return "Default Title"; }
}
add_filter('wp_title', 'assignPageTitle');