如果插件处于活动状态则显示元素。如果不隐藏元素

我正在使用带有 Mailchimp 插件的 Wordpress。


我在 footer.php 文件中创建了以下代码:


<div class="subscribe">

  <div class="subscribe-body">

    <h3>Subscribe</h3>

    <?php echo do_shortcode( '[mc4wp_form id="2501"]' ); ?>

  </div>

</div> 

现在我尝试在插件处于活动状态时显示代码,如果插件处于非活动状态则隐藏代码。


我在 WordPress 上找到了这方面的手册,但我还是个初学者。


aluckdog
浏览 104回答 3
3回答

慕田峪4524236

如何 ?/**&nbsp;* Detect plugin. For use on Front End only.&nbsp;*/include_once( ABSPATH . 'wp-admin/includes/plugin.php' );// check for plugin using plugin nameif ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) {&nbsp;<div class="subscribe">&nbsp; <div class="subscribe-body">&nbsp; &nbsp; <h3>Subscribe</h3>&nbsp; &nbsp; <?php echo do_shortcode( '[mc4wp_form id="2501"]' ); ?>&nbsp; </div>&nbsp;</div>&nbsp;}

素胚勾勒不出你

正确的代码&nbsp; &nbsp;/**&nbsp; &nbsp; &nbsp;* Detect plugin. For use on Front End only.&nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; include_once( ABSPATH . 'wp-admin/includes/plugin.php' );&nbsp; &nbsp; add_action( 'wp_footer', 'add_footer_code' );&nbsp; &nbsp; function add_footer_code(){&nbsp; &nbsp; &nbsp; &nbsp;// check for plugin using plugin name&nbsp; &nbsp; &nbsp; &nbsp;if ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) {?>&nbsp; &nbsp; &nbsp; &nbsp; <div class="subscribe">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<div class="subscribe-body">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h3>Subscribe</h3>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php echo do_shortcode( '[mc4wp_form id="2501"]' ); ?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; &nbsp;}&nbsp;&nbsp; &nbsp; }如果您想在前端添加条件,请使用以下代码include_once( ABSPATH . 'wp-admin/includes/plugin.php' );// check for plugin using plugin nameif ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) {&nbsp; &nbsp; //plugin is activated}如果您只想在后端添加条件,请使用以下代码if ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) {&nbsp; &nbsp; //plugin is activated}如果您想在后端和前端都添加条件,请使用以下代码// check for plugin using plugin nameif(in_array('plugin-directory/plugin-file.php', apply_filters('active_plugins', get_option('active_plugins')))){&nbsp;&nbsp; &nbsp; //plugin is activated}

慕勒3428872

您可以尝试 is_plugin_active() Wordpress 函数。在 function.php 中通过更改文件路径来编写此内容。&nbsp; &nbsp; <?php&nbsp; &nbsp; /**&nbsp; &nbsp; &nbsp;* Detect plugin. For use on Front End only.&nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; include_once( ABSPATH . 'wp-admin/includes/plugin.php' );&nbsp; &nbsp; &nbsp;add_action( 'wp_footer', 'add_footer_code' );&nbsp; &nbsp; &nbsp;function add_footer_code(){&nbsp; &nbsp; // check for plugin using plugin name&nbsp; &nbsp; if ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) {&nbsp; &nbsp; &nbsp; &nbsp; //plugin is activated?>&nbsp;<div class="subscribe">&nbsp; <div class="subscribe-body">&nbsp; &nbsp; <h3>Subscribe</h3>&nbsp; &nbsp; <?php echo do_shortcode( '[mc4wp_form id="2501"]' ); ?>&nbsp; </div><?php&nbsp; &nbsp; }&nbsp;&nbsp; &nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5