remove visual composer from one single page wordpress - wordpress

I am using a paid plugin "Visual Composer". I want to remove the visual composer from one specific page. But I have tried from screen options and from acf too. Still visual composer still appears.

It can be filtered when WP pulls all active plugins. We check if it's admin side and if the current admin page is correct, then check the URL to see if post with ID 2 (Sample Page) is being edited, and finally remove the plugin from the option list:
add_filter( 'option_active_plugins', function ( $option )
{
global $pagenow;
if( 'post.php' !== $pagenow || !is_admin() )
return $option;
if( !isset( $_GET['post'] ) || '2' !== $_GET['post'] )
return $option;
return array_diff( $option, array( 'js_composer/js_composer.php' ) );
});

Can you remove the buttons via javascript or CSS by targeting the .composer-switch class.
.composer-switch {
display:none;
}
This would remove the buttons on that page if you combine it with the PHP at top.

If you mean "remove visual composer" on the front-end view you can use this plugin: Plugin organizer
Just install, activate the option "Selective plugin loading" as on the screen capture
And go thru wordpress admin to the page you want to disable Visual composer, scroll down to find the Plugin organizer options" and disable "visual composer" for that page just dragging and dropping to one side or another. You can do it for any page you want.

You can use the vc_is_valid_post_type_be filter to completely disable the backend and frontend editor like so:
// Disable WPBakery on certain pages
add_filter( 'vc_is_valid_post_type_be', 'disable_wpbakery', 10, 2 );
function disable_wpbakery( $enabled, $post_type ) {
global $post;
// Replace with the condition of your choice
if ( in_array( get_post_meta( $post->ID, '_wp_page_template', true ), [
'my-template.php',
'other-template.php'
] ) ) {
// Optionally disable the classic editor
//remove_post_type_support( 'page', 'editor' );
return false;
}
return $enabled;
}

Related

Disable Elementor on specific page

I have a plugin that uses the default woocommerce my account shortcode and displays the page only for a specific role. But, I have customized the My Account page using elementor & crocoblock, and the plugin is not working properly. They did give a workaround for this in the documentation, but I can't seem to make it work. This is the code
add_filter( 'elementor/frontend/the_content', 'wcb2bsa_disable_elementor_on_sales_agents_area' );
function wcb2bsa_disable_elementor_on_sales_agents_area( $content ) {
if ( is_account_page() && is_user_logged_in() && wcb2bsa_has_role( get_current_user_id(), 'sales_agent' ) ) {
return '[woocommerce_my_account]';
}
return $content;
}
Is it because the elementor/frontend/the_content part is changed?

How to disable specific plugin on Wordpress backend / edit product page

I try to find a solution to disable specific plugins on Wordpress admin area. The problem is that for building WooCommerce shops I use Divi Builder, which on product page can sometimes use 50mb of resources when you try to edit it... if I disable some plugins over there then the load time would be much faster. I've found the following code on other topic:
add_filter( 'option_active_plugins', 'lg_disable_cart66_plugin' );
function lg_disable_cart66_plugin($plugins){
if(strpos($_SERVER['REQUEST_URI'], '/store/') === FALSE AND strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === FALSE) {
$key = array_search( 'cart66/cart66.php' , $plugins );
if ( false !== $key ) unset( $plugins[$key] );
}
return $plugins;
}
But don't know how to modify it, so it only disables the chosen plugin on backend. In other words: I don't want the plugin to load when I edit WooCommerce product page.
Some help will be really appreciated.
As ‘option_active_plugins’ is fired before any plugin is loaded we need to drop our code down into mu-plugins directory. Please also remember that those plugins are run before the main query is initialized – that is why we don’t have any access to many functionalities, especially conditional tags which will always return false.
Please paste below code or download gist in mu-plugins folder in your wp-content folder. It would disable the plugin in post & page areas only.
<?php
/*
Plugin Name: Disable Plugin for URl
Plugin URI: https://www.glowlogix.com
Description: Disable plugins for for specific backend pages.
Author: Muhammad Usama M.
Version: 1.0.0
*/
add_filter( 'option_active_plugins', 'disable_plugins_per_page' );
function disable_plugins_per_page( $plugin_list ) {
// Quit immediately if not post edit area.
global $pagenow;
if (( $pagenow == 'post.php' || $pagenow == 'edit.php' )) {
$disable_plugins = array (
// Plugin Name
'hello.php',
'developer/developer.php'
);
$plugins_to_disable = array();
foreach ( $plugin_list as $plugin ) {
if ( true == in_array( $plugin, $disable_plugins ) ) {
//error_log( "Found $plugin in list of active plugins." );
$plugins_to_disable[] = $plugin;
}
}
// If there are plugins to disable then remove them from the list,
// otherwise return the original list.
if ( count( $plugins_to_disable ) ) {
$new_list = array_diff( $plugin_list, $plugins_to_disable );
return $new_list;
}
}
return $plugin_list;
}
You can replace $disable_plugins with the required list of plugins to disable.

How to allow WordPress editors (role) to put code in WYSIWSG textarea?

In WordPress, I have a custom field where I need some editors (WordPress role) to put some html+javascript code.
It seems that WordPress clean the code when you're not an administrator.
Is there a hook or option that I can edit in order to let them add those codes (embed, forms, ...)?
I tried to put some javascript code with the admin role, ok.
I tried with editor role, ko.
So, I'm pretty sure the problem comes from there.
Ok, after further review and a look in wordpress core functions, here's the answer.
In multisite, editors don't have 'unfiltered_html' capability.
So you just have to had it:
<?php
function add_custom_capability_to_editors( $caps, $cap, $user_id ) {
if ( 'unfiltered_html' === $cap && user_can( $user_id, 'editor' ) ) {
$caps = array( 'unfiltered_html' );
}
return $caps;
}
add_filter( 'map_meta_cap', 'add_custom_capability_to_editors', 1, 3 );

hide wordpress posts and categories for not logged in users

Basically I handled this issue by overriding parent theme files in child theme.
i.e., by using
if( is_user_logged_in() ){
...................
wordpress loop
}
I had to do this for every template ( wherever there is wordpress loop )
Though I didn't have to do this for displaying sidebars as if there was category in widget and whenever user clicks on it to view it, it would automatically say you don't have proper privileges to view this content.
So, my question is, is there any better way to hide wordpress content ( this may be anything, like normal posts, custom post types,.. ) from just visitors.
function bt_hide_from_guestes( $content ) {
global $post;
if ( $post->post_type == 'post' ) {
if ( !is_user_logged_in() ) {
$content = 'Please login to view this post';
}
}
return $content;
}
add_filter( 'the_content', 'bt_hide_from_guestes' );
Above code didn't help
It looks like your filter function should work for you. Try setting a priority and the "accepted arg" number:
add_filter( 'the_content', 'bt_hide_from_guestes', 10, 1 );

Disable Shop page on Woocommerce to protect categories

Im trying to disable "shop" page in Woocommerce. Basically im creating a shop theme to sell prints and image downloads for a photographer.
Because i need to create private galleries i created a custom post type where i use the woocommerce category shortcode to show products and then i password protect the post type.
This is a workaround for password protecting the woocommerce categories (if someone knows a better one please explain).
The problem is that is someone goes to /shop they will all products, including the "protected ones". So i need to disable the shop page and i need to do it programmatically on my theme functions. Any thoughts?
To disable the shop page, copy over the archive-product.php file from the /wp-content/plugins/woocommerce/templates/archive-product.php and put in /wp-content/themes/{Your Theme}/woocommerce/archive-product.php
Open up the file and overwrite everything in file with the following code below:
<?php
global $wp_query;
$wp_query->set_404();
status_header(404);
get_template_part('404');
Save the file, and now your Shop page is gone and replaced with a 404 Page!
Add this to functions:
function woocommerce_disable_shop_page() {
global $post;
if (is_shop()):
global $wp_query;
$wp_query->set_404();
status_header(404);
endif;
}
add_action( 'wp', 'woocommerce_disable_shop_page' );
Docs: WooCommerce Conditional Functions Documentation
WooCommerce has a filter for the array that it uses to create the Product post type: woocommerce_register_post_type_product.
Rather changing the archive template to force it to redirect, you can completely remove the post type’s archive, but changing the has_archive attribute on the post type on creation.
add_filter('woocommerce_register_post_type_product', function($post_type) {
$post_type['has_archive'] = false;
return $post_type;
});
You should then remove the shop page in the CMS by going to WooCommerce » Settings » Product » Display, and clicking the “x” on the “Shop Page” option.
You might need to flush the permalink cache, which you can do just by clicking the “Update” button in Settings » Permalinks.
*Edit -
Apparently the page setting I suggested below no longer works. If WooCommerce doesn't have a plugin setting to change it, I personally would use a wordpress redirect plugin like Redirection. This way you can automatically redirect them from the undesired shop page to whatever page displays your products. It avoids a 404 issue and keeps everything in tact. It also avoids editing template files which adds complications to non-developers.
Old Answer:
Have you tried Woo settings?
Admin area, left main menu, Woocommerce > Settings
Click the pages tab.
Under Pages setup is "Shop Base Page", on the dropdown, there's a small "x" to right right. Click that to get rid of the page.
If there are links elsewhere that need to be fixed let me know and I'll find the hooks/filters to remedy it.
template_redirect is the last hook before page render so in my use case I ask if the page being viewed is the "shop" page and if it is I redirect to (in my case) a pricing page.
function my__template_redirect(){
if(is_shop()){
wp_redirect(site_url() . '/pricing/', '302');
}
}
add_action('template_redirect', 'my__template_redirect');
The last suggestion didn't work for me with WP 4.6.1 and WooCommerce 2.6.4. Hiding products in the Publish tab works for me.
http://paperhedge.com/hide-products-from-displaying-in-shop-page-woocommerce/
To disable the default shop page and leave the /shop/ slug free for custom pages use this:
function remove_woocommerce_default_shop( $args, $post_type ) {
if (class_exists('WooCommerce')) {
if ( $post_type == "product" ) {
$args['has_archive'] = true;
}
return $args;
}
}
add_filter('register_post_type_args', 'remove_woocommerce_default_shop', 20, 2);
You need to hook a couple (or maybe more) things:
/* hide category from shop pages */
add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $q ) {
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() ) {
$q->set( 'tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( YOUR-CATEGORY-SLUG, YOUR-CATEGORY-SLUG-2 ), // Don't display products in the knives category on the shop page
'operator' => 'NOT IN'
)));
}
remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
}
Change, obviusly YOUR-CATEGORY-SLUG, YOUR-CATEGORY-SLUG-2 for your cat or cats to hide from shop pages.
Then, you need to hide them from menues too, right?:
/* hide category from menues */
add_filter( 'get_terms', 'get_subcategory_terms', 10, 3 );
function get_subcategory_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
// if category and on the shop page (change it with is_woocommerce() if want to hide from all woo pages)
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) {
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->slug, array( YOUR-CATEGORY-SLUG, YOUR-CATEGORY-SLUG-2 ) ) ) {
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
But i don´t think this solve 100% the thing, since then, what about search results?
Try this
Create new page named "Shop"
Go to "woocommerce" > "Settings" > "Product" > "Display tab"
Select shop page named "Shop" then click save changes
Back to "Pages" then delete "Shop" page (keep the page on trash,
don't delete permanently)
This method works fine for me

Resources