Search

הסרת Jetpack CSS

התוסף Jetpack מוסיף עשרות אפשרויות לוורדפרס וניתן להפעיל את הפיצ׳רים בו במידת הצורך ולבחירתכם. בזמן כתיבת סניפט זה, במקום ש Jetpack תטען את ה styling בהתאם לפיצ׳רים שבחרתם, היא טוענת קובץ אחד גדול המכיל את כל ה css של כל הפיצ׳רים.

נתקלתי במצב בו אני צריך להשתמש רק בפיצ׳ר קטן ופשוט שאינו מצריך css, וזה הפיטצ׳ר של הרשמה לפוסטים ותגובות. בכדי לבטל את הטעינה של ה css המיותר השתמשתי בקוד זה functions.php:


// First, make sure Jetpack doesn't concatenate all its CSS
add_filter( 'jetpack_implode_frontend_css', '__return_false' );

// Then, remove each CSS file, one at a time
function jeherve_remove_all_jp_css() {
  wp_deregister_style( 'AtD_style' ); // After the Deadline
  wp_deregister_style( 'jetpack_likes' ); // Likes
  wp_deregister_style( 'jetpack_related-posts' ); //Related Posts
  wp_deregister_style( 'jetpack-carousel' ); // Carousel
  wp_deregister_style( 'grunion.css' ); // Grunion contact form
  wp_deregister_style( 'the-neverending-homepage' ); // Infinite Scroll
  wp_deregister_style( 'infinity-twentyten' ); // Infinite Scroll - Twentyten Theme
  wp_deregister_style( 'infinity-twentyeleven' ); // Infinite Scroll - Twentyeleven Theme
  wp_deregister_style( 'infinity-twentytwelve' ); // Infinite Scroll - Twentytwelve Theme
  wp_deregister_style( 'noticons' ); // Notes
  wp_deregister_style( 'post-by-email' ); // Post by Email
  wp_deregister_style( 'publicize' ); // Publicize
  wp_deregister_style( 'sharedaddy' ); // Sharedaddy
  wp_deregister_style( 'sharing' ); // Sharedaddy Sharing
  wp_deregister_style( 'stats_reports_css' ); // Stats
  wp_deregister_style( 'jetpack-widgets' ); // Widgets
  wp_deregister_style( 'jetpack-slideshow' ); // Slideshows
  wp_deregister_style( 'presentations' ); // Presentation shortcode
  wp_deregister_style( 'jetpack-subscriptions' ); // Subscriptions
  wp_deregister_style( 'tiled-gallery' ); // Tiled Galleries
  wp_deregister_style( 'widget-conditions' ); // Widget Visibility
  wp_deregister_style( 'jetpack_display_posts_widget' ); // Display Posts Widget
  wp_deregister_style( 'gravatar-profile-widget' ); // Gravatar Widget
  wp_deregister_style( 'widget-grid-and-list' ); // Top Posts widget
  wp_deregister_style( 'jetpack-widgets' ); // Widgets
}
add_action('wp_enqueue_scripts', 'jeherve_remove_all_jp_css' );
מצאתם טעות בקוד? הסניפט לא עובד לכם? רישמו לי בתגובות ואני מבטיח לטפל בכך במהרה ולספק סניפט תקין...
3 תגובות...
  • עדי 22 ינואר 2018, 20:54

    הי! האם ממליץ להשתמש ב-Image CDN של jetpack? ואם כן מה השורה הרלוונטית בקובץ PHP שצירפת שצריך להסיר (כדי שהפונק' הזו אכן תעבוד..)?
    תודה!

    • רועי יוסף 22 ינואר 2018, 22:40

      היי עדי 🙂

      בפונקציה המדוברת אין שורה שרלוונטית ל Image CDN של Jetpack מכיוון שלפונקציונליות זו אין קשר ל CSS כזה או אחר.
      איני יכול להמליץ לגבי שירות זה כי אין לי נסיון מולו, בגדול, אם את במקום שאת צריכה CDN תשקלי לעבוד עם שירות חיצוני כגון MaxCDN וכדומה…

      • עדי 1 פברואר 2018, 1:40

        תודה על התשובה!

תגובה חדשה

Up!
לבלוג