检测视觉作曲家 [英] Detect Visual Composer
问题描述
有没有办法检测 WordPress 页面是否使用 Visual Composer?
Is there a way to detect if a WordPress page is using Visual Composer?
我有 2 个不同的页面模板:
I have 2 different page templates:
- 常规页面的默认模板.
- 视觉编辑器页面模板.
我希望有一种方法可以检测用户是否使用可视化编辑器来构建页面,而不是依赖于用户每次都选择可视化编辑器模板.
I'm hoping there is a way to detect if a user is using visual composer to build the page instead of relying on the user selecting the visual composer template each time.
有没有办法检测正在构建的页面,然后根据它分配模板?
Is there a way to detect what page is being built and then assign a template based on that?
推荐答案
是的,您可以检测是否为帖子启用了可视化编辑器.它存储在 _wpb_vc_js_status
帖子元属性中.
Yes, you can detect if visual composer is enabled for a post. It's stored in the _wpb_vc_js_status
post meta attribute.
$vc_enabled = get_post_meta($post_id, '_wpb_vc_js_status', true);
请注意,即使当前未启用视觉编辑器编辑,帖子仍可以包含视觉编辑器短代码.例如,如果我使用可视化编辑器设置一个页面,然后恢复到普通编辑器,_wpb_vc_js_status
将为 false.
Note that a post can still contain the visual composer shortcodes, even when visual composer editing is not currently enabled. For example, if I setup a page with visual composer and then revert back to the normal editor, _wpb_vc_js_status
will be false.
这篇关于检测视觉作曲家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!