Remove photoswipe-css and photoswipe-default-skin-css in WordPress - wordpress

I am building a custom webshop and I am trying to remove the photoswipe style documents but I can't seem to get rid of them, I tried a couple of "solutions" that I found online but they are not working. This is what I tried so far in the functions.php:
remove_theme_support( 'wc-product-gallery-zoom' );
remove_theme_support( 'wc-product-gallery-lightbox' );
remove_theme_support( 'wc-product-gallery-slider' );
and
add_filter( 'woocommerce_enqueue_styles', 'wpf_dequeue_styles' );
function wpf_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['photoswipe-css'] );
unset( $enqueue_styles['photoswipe-default-skin-css'] );
return $enqueue_styles;
}
and
wp_dequeue_script('photoswipe-css');
wp_dequeue_script('photoswipe-default-skin-css');
Can someone help me finding the solution? I don't have any images in my webshop so I do not need these scripts.

You can remove_theme_support using after_setup_theme action hook.
add_action( 'after_setup_theme', 'remove_photoswipe_css', 11 );
function remove_photoswipe_css() {
remove_theme_support( 'wc-product-gallery-zoom' );
remove_theme_support( 'wc-product-gallery-lightbox' );
remove_theme_support( 'wc-product-gallery-slider' );
}
You can wp_dequeue_style using wp_enqueue_scripts action hook.
add_action( 'wp_enqueue_scripts', 'dequeue_photoswipe_css', 11 );
function dequeue_photoswipe_css() {
wp_dequeue_style( 'photoswipe-css' );
wp_dequeue_style( 'photoswipe-default-skin-css' );
}

If anyone is still looking for the answer to this then the correct code would be :
add_action( 'wp_enqueue_scripts', 'dequeue_photoswipe_css', 99);
function dequeue_photoswipe_css() {
wp_dequeue_style( 'photoswipe' );
wp_dequeue_style( 'photoswipe-default-skin-css' );
wp_dequeue_script( 'photoswipe-ui-default' );
}

Related

Wordpress shortcode not rendering in Yoast og:title

I have a simple shortcode which i use on post titles:
add_shortcode('year', 'year_shortcode');
function year_shortcode() {
$year = date('Y');
return $year;
}
add_filter( 'single_post_title', 'my_shortcode_title' );
add_filter( 'the_title', 'my_shortcode_title' );
add_filter('wpseo_title', 'my_shortcode_title');
add_filter( 'wpseo_metadesc', 'my_shortcode_title' );
function my_shortcode_title( $title ){
return do_shortcode( $title );
}
It works fine but I suddenly realized that Yoast creates an og:title and it doesn't render there (meaning it doesn't render on Facebook or whatsapp)
I searched for an answer and couldn't find anythinng.
Has anyone faced this before?
Maybe I need to run the og:title through a filter of some sort which is also fine, the question is how.
Thanks in advance.
I used this and it mostly works.
It will update the og:title, and socials etc in Yoast.
It does not update Yoast's default Schema output. This would probably need to be addressed by them.
// Create Year shortcode to replace with current year.
add_shortcode( 'currentyear', 'current_year' );
function current_year() {
$year = date( 'Y' );
return $year;
}
// Activate shortcode function in Post Title.
add_filter( 'the_title', 'do_shortcode' );
add_filter( 'single_post_title', 'do_shortcode' );
add_filter( 'wpseo_title', 'do_shortcode' );
add_filter( 'wpseo_metadesc', 'do_shortcode' );
add_filter( 'wpseo_opengraph_title', 'do_shortcode' );
add_filter( 'wpseo_opengraph_desc', 'do_shortcode' );
add_filter( 'wpseo_opengraph_site_name', 'do_shortcode' );
add_filter( 'wpseo_twitter_title', 'do_shortcode' );
add_filter( 'wpseo_twitter_description', 'do_shortcode' );
add_filter( 'the_excerpt', 'do_shortcode' );

How to remove gutenberg_render_title_tag from theme function file?

I have try remove action but not working.
add_action( 'wp_loaded', 'remove_my_action' );
function remove_my_action() {
remove_action( 'wp_head', 'gutenberg_render_title_tag', -1 );
}
or
add_action( 'init', 'remove_my_action' );
function remove_my_action() {
remove_action( 'wp_head', 'gutenberg_render_title_tag', -1 );
}
i am using yoast plugin. Yoast plugin also using remove action https://github.com/Yoast/wordpress-seo/blob/trunk/src/integrations/front-end-integration.php#L220 but it's not working. Still tag coming two time. i wants to remove gutenberg title tag.
I got the solution for this.
add_action( 'wp', 'remove_default_guten_title' );
function remove_default_guten_title() {
foreach ( gutenberg_get_template_type_slugs() as $template_type ) {
add_filter( str_replace( '-', '', $template_type ) . '_template', 'remove_default_title', 21, 3 );
}
}
function remove_default_title() {
remove_action( 'wp_head', 'gutenberg_render_title_tag', 1 );
return gutenberg_dir_path() . 'lib/template-canvas.php';
}

PHP 7.3 Function create_function() is deprecated

I have used create_function in my theme below.
add_action( 'widgets_init', create_function( '', 'register_widget( "Woocommerce_Header_Cart" );' ) );
But for PHP 7.3.0, the create_function() is deprecated.
Any idea, how to fix my codes above on PHP 7.3.0.
Thanks for your help,
Try this code
add_action( 'widgets_init', 'custom_widget_func');
funcation custom_widget_func(){
register_widget( "Woocommerce_Header_Cart" );
}
Replace
add_action( 'widgets_init', create_function( '', 'register_widget( "Woocommerce_Header_Cart" );' ) );
with this, using an anonymous function instead :
add_action( 'widgets_init', function() { return register_widget("Woocommerce_Header_Cart"); } );

WP | Dequeque Styles from Calculated Fields Form

My wp dequeque function in the functions.php isn't removing the styles from the plugin "Calculated Fields Form". How can I remove these styles from my page?
My function:
// Remove CFF Styles
function remove_calcform_styles() {
wp_dequeue_style( 'cpcff_stylepublic' );
wp_dequeue_style( 'cpcff_jquery_ui' );
wp_dequeue_style( 'cpcff_template_csscp_cff_11' );
}
add_action( 'wp_enqueue_scripts', 'remove_calcform_styles', 999 );
In Calculated Form fields plugin wp_enqueue_style used directly, that's why when you add hook for the wp_enqueue_scripts nothing happens.
Try to add hook for the init action:
function remove_calcform_styles() {
wp_dequeue_style( 'cpcff_stylepublic' );
wp_dequeue_style( 'cpcff_jquery_ui' );
wp_dequeue_style( 'cpcff_template_csscp_cff_11' );
}
add_action( 'init', 'remove_calcform_styles', 10 );
UPDATE
Try also plugins_loaded action:
add_action( 'plugins_loaded', 'remove_calcform_styles', 10 );

Remove Contact Form 7 CSS and JS Unless Contact form 7 shortcode is used in the page

I want to show the css and javascript only when the shortcode is used in that page. If the short code not present in the wordpress page then the js and css of contact form should not be shown. For that what i have done is i have pasted the following code in my active themes function.php file.
add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );
The above code totally removes the js and css of contact form 7 plugin. What i need is if contact form 7 shortcode is pasted then both should be shown.
Here is the answer for your question. If there is not shortcode the css and js of contact form will be removed and if there is shortcode css and js will be added.
function rjs_lwp_contactform_css_js() {
global $post;
if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'contact-form-7') ) {
wp_enqueue_script('contact-form-7');
wp_enqueue_style('contact-form-7');
}else{
wp_dequeue_script( 'contact-form-7' );
wp_dequeue_style( 'contact-form-7' );
}
}
add_action( 'wp_enqueue_scripts', 'rjs_lwp_contactform_css_js');
I needed the other version that corresponds widgets and shortcodes in theme file.
add_filter( 'wpcf7_load_css', '__return_false' );
add_filter( 'wpcf7_load_js', '__return_false' );
remove_action( 'wp_enqueue_scripts','wpcf7_recaptcha_enqueue_scripts', 20 );
add_filter('pre_do_shortcode_tag', 'enqueue_wpcf7_css_js_as_needed', 10, 2 );
function enqueue_wpcf7_css_js_as_needed ( $output, $shortcode ) {
if ( 'contact-form-7' == $shortcode ) {
wpcf7_recaptcha_enqueue_scripts();
wpcf7_enqueue_scripts();
wpcf7_enqueue_styles();
}
return $output;
}
You use below code.You can add your pages Id in this code.
function dvk_dequeue_scripts() {
$load_scripts = false;
if( is_singular() ) {
$post = get_post();
if( has_shortcode($post->post_content, 'contact-form-7') ) {
$load_scripts = true;
}
}
if( ! $load_scripts ) {
wp_dequeue_script( 'contact-form-7' );
wp_dequeue_style( 'contact-form-7' );
}
}
add_action( 'wp_enqueue_scripts', 'dvk_dequeue_scripts', 99 );
Reference

Resources