CSS-TricksWordPress Snippets Feed | CSS-Tricks https://css-tricks.com Tips, Tricks, and Techniques on using Cascading Style Sheets. Fri, 05 Apr 2024 22:21:03 +0000 hourly 1 https://wordpress.org/?v=6.5.2 https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/07/star.png?fit=32%2C32&ssl=1 WordPress Snippets Feed | CSS-Tricks https://css-tricks.com 32 32 45537868 Removing Jetpack CSS https://css-tricks.com/snippets/wordpress/removing-jetpack-css/ https://css-tricks.com/snippets/wordpress/removing-jetpack-css/#comments Wed, 10 Dec 2014 21:45:43 +0000 Chris Coyier http://css-tricks.com/?page_id=190541 Jetpack is a WordPress plugin that brings a ton of features to WordPress. You turn on the features as needed. At the time of this writing, rather than include a separate CSS file for each feature as needed, they load …

]]>
Jetpack is a WordPress plugin that brings a ton of features to WordPress. You turn on the features as needed. At the time of this writing, rather than include a separate CSS file for each feature as needed, they load a large concatenated stylesheet with all the CSS together.

I was in a position where I was using a few Jetpack features but actually needed none of the CSS.

Update! As of January 2019 (JetPack 6.9), this is what you need (for functions.php, or functionality plugin) below:

add_filter( 'jetpack_sharing_counts', '__return_false', 99 );
add_filter( 'jetpack_implode_frontend_css', '__return_false', 99 );

I’ll keep this around for historical reasons, as this is what used to be required:

// 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_print_styles', 'jeherve_remove_all_jp_css' );

Thanks to Jon Bellah, TJ Kelly, George Stephanis, and everyone else who chimed in to help me.

I suspect this will change over time. It seems to me the best possible way to do this would be to serve a concatenated stylesheet for just the featured you have turned on, and have a single named thing you can deregister.

]]>
https://css-tricks.com/snippets/wordpress/removing-jetpack-css/feed/ 19 190541
Increase Custom Fields Dropdown Limit https://css-tricks.com/snippets/wordpress/increase-custom-fields-dropdown-limit/ https://css-tricks.com/snippets/wordpress/increase-custom-fields-dropdown-limit/#comments Mon, 11 Aug 2014 15:59:07 +0000 Chris Coyier http://css-tricks.com/?page_id=178550 For your functions.php file or custom plugin:

// Increase number of meta fields shown in dropdown
add_filter('postmeta_form_limit', 'customfield_limit_increase');
function customfield_limit_increase($limit) {
  $limit = 100;
  return $limit;
}

Otherwise, the dropdown for Custom Fields is capped at 30 (alphabetically).

Before:

After:…

]]>
For your functions.php file or custom plugin:

// Increase number of meta fields shown in dropdown
add_filter('postmeta_form_limit', 'customfield_limit_increase');
function customfield_limit_increase($limit) {
  $limit = 100;
  return $limit;
}

Otherwise, the dropdown for Custom Fields is capped at 30 (alphabetically).

Before:

After:

]]>
https://css-tricks.com/snippets/wordpress/increase-custom-fields-dropdown-limit/feed/ 5 178550
the_category with Excludes https://css-tricks.com/snippets/wordpress/the_category-excludes/ https://css-tricks.com/snippets/wordpress/the_category-excludes/#comments Mon, 14 Jul 2014 22:03:32 +0000 Chris Coyier http://css-tricks.com/?page_id=175410 The WordPress function the_category doesn’t offer an exclude parameter. This does:

function exclude_post_categories($excl='', $spacer=' ') {
  $categories = get_the_category(get_the_ID());
  if (!empty($categories)) {
    $exclude = $excl;
    $exclude = explode(",", $exclude);
    $thecount = count(get_the_category()) - count($exclude);
    foreach ($categories as $cat) {
      $html 
…]]>
The WordPress function the_category doesn’t offer an exclude parameter. This does:

function exclude_post_categories($excl='', $spacer=' ') {
  $categories = get_the_category(get_the_ID());
  if (!empty($categories)) {
    $exclude = $excl;
    $exclude = explode(",", $exclude);
    $thecount = count(get_the_category()) - count($exclude);
    foreach ($categories as $cat) {
      $html = '';
      if (!in_array($cat->cat_ID, $exclude)) {
        $html .= '<a href="' . get_category_link($cat->cat_ID) . '" ';
        $html .= 'title="' . $cat->cat_name . '">' . $cat->cat_name . '</a>';
        if ($thecount > 0) {
          $html .= $spacer;
        }
        $thecount--;
        echo $html;
      }
    }
  }
}

Plus as long as you have that, you can alter the output however you want which is nice.

Usage is like:

<?php exclude_post_categories("4"); ?>

Which would list all categories excluding the one with the ID of 4.

]]>
https://css-tricks.com/snippets/wordpress/the_category-excludes/feed/ 6 175410
Get Featured Image URL https://css-tricks.com/snippets/wordpress/get-featured-image-url/ https://css-tricks.com/snippets/wordpress/get-featured-image-url/#comments Sat, 22 Feb 2014 16:48:39 +0000 Chris Coyier http://css-tricks.com/?page_id=163741 Post thumbnails are pretty useful and pretty easy to use in WordPress. Simply add:

add_theme_support('post-thumbnails'); 

To a theme’s functions.php file and you’ll get a Featured Image module on the admin screen for posts which allows you to select one.

It …

]]>
Post thumbnails are pretty useful and pretty easy to use in WordPress. Simply add:

add_theme_support('post-thumbnails'); 

To a theme’s functions.php file and you’ll get a Featured Image module on the admin screen for posts which allows you to select one.

It is also very easy to output that image as an HTML <img>:

get_the_post_thumbnail();

But what if you just need the URL? Say, you’re going to use it as a background-image on an element rather than a content image. Unfortunately there is no super easy/obvious function for that.

Within the loop, you’ll have to do:

$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true);
$thumb_url = $thumb_url_array[0];

Then $thumb_url will be that URL.

]]>
https://css-tricks.com/snippets/wordpress/get-featured-image-url/feed/ 27 163741
Add Category Name to body_class https://css-tricks.com/snippets/wordpress/add-category-name-body_class/ https://css-tricks.com/snippets/wordpress/add-category-name-body_class/#comments Sat, 22 Feb 2014 16:44:23 +0000 Chris Coyier http://css-tricks.com/?page_id=163742 The body_class function is nice for adding a bunch of classes to the body tag that have information about what kind of page is currently being displayed. Probably for styling purposes. But for whatever reason, it doesn’t include a class …

]]>
The body_class function is nice for adding a bunch of classes to the body tag that have information about what kind of page is currently being displayed. Probably for styling purposes. But for whatever reason, it doesn’t include a class for the current category (or categories) for a single post.

This adds that category “nice” name:

add_filter('body_class','add_category_to_single');
  function add_category_to_single($classes) {
    if (is_single() ) {
      global $post;
      foreach((get_the_category($post->ID)) as $category) {
        // add category slug to the $classes array
        $classes[] = $category->category_nicename;
      }
    }
    // return the $classes array
    return $classes;
  }
]]>
https://css-tricks.com/snippets/wordpress/add-category-name-body_class/feed/ 18 163742