【问题标题】:Detect whether WordPress plugin is present检测是否存在 WordPress 插件
【发布时间】:2012-09-03 04:20:03
【问题描述】:

有没有办法检测WordPress中是否存在插件并输出条件代码?

这就是我想要这样做的原因......

我正在使用 WordPress SEO Yoast 插件,并且需要更改默认标题标签以使其正常工作,例如

<title>
    <?php
        wp_title( '|', true, 'right' );
    ?>
</title>

需要改成...

<title><?php wp_title(''); ?></title>

这很好,但是如果我卸载了 SEO Yoast 并且忘记切换回代码怎么办?为了安全起见,我希望有一些条件代码说..

如果存在SEO Yoast插件,则更改标题代码,如果没有,则输出默认标题代码。

有没有简单的方法来做到这一点?

谢谢

【问题讨论】:

    标签: wordpress plugins


    【解决方案1】:

    你可以试试is_plugin_active函数(在前端,在主题等)

    <?php 
        include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
        If (is_plugin_active('plugin-directory/plugin-file.php')) {
    
            //plugin is activated
        }
        else
        {
            //plugin is not activated
        }
    ?>
    

    More here.

    更新:

    <?php
        include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
        if (is_plugin_active('wordpress-seo/wp-seo.php')) { 
            ?><title><?php wp_title(''); ?></title><?php
        } else {
    
            ?><title><?php wp_title( '|', true, 'right' ); ?></title><?php
        }
     ?>
    

    【讨论】:

    • 太好了,非常感谢。这是其他有相同问题的人的最终代码... <?php wp_title(''); ?> <?php wp_title( '|', true, 'right' ); ?>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-30
    • 2017-03-28
    • 1970-01-01
    • 2013-11-24
    • 1970-01-01
    • 2013-04-12
    相关资源
    最近更新 更多