3 回答
TA贡献1875条经验 获得超5个赞
如何 ?
/**
* Detect plugin. For use on Front End only.
*/
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// check for plugin using plugin name
if ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) {
<div class="subscribe">
<div class="subscribe-body">
<h3>Subscribe</h3>
<?php echo do_shortcode( '[mc4wp_form id="2501"]' ); ?>
</div>
</div>
}
TA贡献1827条经验 获得超9个赞
正确的代码
/**
* Detect plugin. For use on Front End only.
*/
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
add_action( 'wp_footer', 'add_footer_code' );
function add_footer_code(){
// check for plugin using plugin name
if ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) {?>
<div class="subscribe">
<div class="subscribe-body">
<h3>Subscribe</h3>
<?php echo do_shortcode( '[mc4wp_form id="2501"]' ); ?>
</div>
</div>
<?php
}
}
如果您想在前端添加条件,请使用以下代码
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// check for plugin using plugin name
if ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) {
//plugin is activated
}
如果您只想在后端添加条件,请使用以下代码
if ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) {
//plugin is activated
}
如果您想在后端和前端都添加条件,请使用以下代码
// check for plugin using plugin name
if(in_array('plugin-directory/plugin-file.php', apply_filters('active_plugins', get_option('active_plugins')))){
//plugin is activated
}
TA贡献1848条经验 获得超6个赞
您可以尝试 is_plugin_active() Wordpress 函数。在 function.php 中通过更改文件路径来编写此内容。
<?php
/**
* Detect plugin. For use on Front End only.
*/
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
add_action( 'wp_footer', 'add_footer_code' );
function add_footer_code(){
// check for plugin using plugin name
if ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) {
//plugin is activated
?>
<div class="subscribe">
<div class="subscribe-body">
<h3>Subscribe</h3>
<?php echo do_shortcode( '[mc4wp_form id="2501"]' ); ?>
</div>
<?php
}
}
- 3 回答
- 0 关注
- 103 浏览
添加回答
举报