admin管理员组文章数量:1130349
Good day! just wondering if you can help me out? I was trying to create a code for functions.php if the user currently lands on a specific page, thus the plugin will turn deactivated, but if the user re jumps on other pages, the plugin would be re activated.
Here's my code.
function disable_plugins(){
if( is_page(2690) ) {
deactivate_plugins( '/popup-maker/popup-maker.php');
} else {
//reactivate the plugin
}
} add_filter('option_active_plugins', 'disable_plugins');
Good day! just wondering if you can help me out? I was trying to create a code for functions.php if the user currently lands on a specific page, thus the plugin will turn deactivated, but if the user re jumps on other pages, the plugin would be re activated.
Here's my code.
function disable_plugins(){
if( is_page(2690) ) {
deactivate_plugins( '/popup-maker/popup-maker.php');
} else {
//reactivate the plugin
}
} add_filter('option_active_plugins', 'disable_plugins');
Share
Improve this question
asked Oct 18, 2018 at 10:30
rrwrrw
1
2
- 2 This is entirely the wrong approach. It should not be necessary to disable a plugin entirely just because you don't want a pop-up to appear on a single page. It's overkill, and a hack. Look at the plugin's documentation to find a supported way to disable the pop-up on a specific page, or ask the author for help. If that doesn't work find a plugin that does support this feature. – Jacob Peattie Commented Oct 18, 2018 at 11:52
- 1 if you deactivate a plugin by a users page visit, you would deactivate it entirely, also for every other user.. so yeah, your approach is kinda wrong here.. – honk31 Commented Oct 18, 2018 at 13:41
1 Answer
Reset to default 2Instead of deactivating the plugin completely (which would deactivate it everywhere on your site) look at the plugin's code and determine what JS and CSS it is enqueuing. Then in your theme's functions.php you can dequeue that plugin's JS/CSS - but only on whatever pages you want to disable the plugin on.
So for example, for the plugin Authorizer, if you want to remove the CSS from two pages, "about" and "contact":
add_action('wp_print_styles', 'wpse_317011_dequeue_authorizer');
function wpse_317011_dequeue_authorizer() {
if(is_page('about') || is_page('contact')) {
wp_dequeue_style('authorizer-public-css');
wp_deregister_style('authorizer-public-css');
}
}
Just replace authorizer-public-css with whatever CSS file you need to from your specific plugin. And dequeue JS as well, if that's needed.
Other conditionals like is_singular() work here too in case it's not just Pages you're dealing with.
Good day! just wondering if you can help me out? I was trying to create a code for functions.php if the user currently lands on a specific page, thus the plugin will turn deactivated, but if the user re jumps on other pages, the plugin would be re activated.
Here's my code.
function disable_plugins(){
if( is_page(2690) ) {
deactivate_plugins( '/popup-maker/popup-maker.php');
} else {
//reactivate the plugin
}
} add_filter('option_active_plugins', 'disable_plugins');
Good day! just wondering if you can help me out? I was trying to create a code for functions.php if the user currently lands on a specific page, thus the plugin will turn deactivated, but if the user re jumps on other pages, the plugin would be re activated.
Here's my code.
function disable_plugins(){
if( is_page(2690) ) {
deactivate_plugins( '/popup-maker/popup-maker.php');
} else {
//reactivate the plugin
}
} add_filter('option_active_plugins', 'disable_plugins');
Share
Improve this question
asked Oct 18, 2018 at 10:30
rrwrrw
1
2
- 2 This is entirely the wrong approach. It should not be necessary to disable a plugin entirely just because you don't want a pop-up to appear on a single page. It's overkill, and a hack. Look at the plugin's documentation to find a supported way to disable the pop-up on a specific page, or ask the author for help. If that doesn't work find a plugin that does support this feature. – Jacob Peattie Commented Oct 18, 2018 at 11:52
- 1 if you deactivate a plugin by a users page visit, you would deactivate it entirely, also for every other user.. so yeah, your approach is kinda wrong here.. – honk31 Commented Oct 18, 2018 at 13:41
1 Answer
Reset to default 2Instead of deactivating the plugin completely (which would deactivate it everywhere on your site) look at the plugin's code and determine what JS and CSS it is enqueuing. Then in your theme's functions.php you can dequeue that plugin's JS/CSS - but only on whatever pages you want to disable the plugin on.
So for example, for the plugin Authorizer, if you want to remove the CSS from two pages, "about" and "contact":
add_action('wp_print_styles', 'wpse_317011_dequeue_authorizer');
function wpse_317011_dequeue_authorizer() {
if(is_page('about') || is_page('contact')) {
wp_dequeue_style('authorizer-public-css');
wp_deregister_style('authorizer-public-css');
}
}
Just replace authorizer-public-css with whatever CSS file you need to from your specific plugin. And dequeue JS as well, if that's needed.
Other conditionals like is_singular() work here too in case it's not just Pages you're dealing with.
本文标签: phpdeactivating an active plugin using if page
版权声明:本文标题:php - deactivating an active plugin using if page 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749250882a2339676.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论