Snippets - Sources

SleekByte allows you to organize snippets across multiple directories and see them all in one unified interface. This flexible source system lets you store snippets in theme directories, plugin folders, or any custom location while maintaining a single management interface.

Default snippet location

When no custom sources are configured, SleekByte uses a default directory inside your WordPress uploads folder:

            /wp-content/uploads/sleek-byte/
  
                    
Copy

This location ensures snippets remain accessible and writable by WordPress while being isolated from core WordPress files.

Understanding snippet sources

A snippet source is a named directory location where SleekByte looks for snippet folders. Each source appears as a top-level section in the file browser, making it easy to organize snippets by project, functionality, or origin.

Source properties

Each snippet source has three key properties:

name (string)
Display name shown in the SleekByte file browser. Must be unique across all sources since it appears as a top-level folder in the interface.

path (string)
Absolute filesystem path to the directory containing snippet folders.

sort (int)
Display order in the file browser. Lower numbers appear first. Default sources use 100.

Adding custom sources

Use the sleekByte/snippets/paths filter to add custom snippet directories. This allows you to organize snippets across multiple locations while managing them from a single interface.

            add_filter('sleekByte/snippets/paths', function ($sources) {
      // Add custom snippets directory
      $sources[] = [
        'name' => 'Custom Snippets',
        'path' => get_template_directory() . '/snippets',
        'sort' => 50,
      ];

      // Add another directory for client-specific snippets
      $sources[] = [
        'name' => 'Client Snippets',
        'path' => WP_CONTENT_DIR . '/client-snippets',
        'sort' => 75,
      ];

      return $sources;
    });
  
                    
Copy

This example adds two new sources:

  • Custom Snippets - Located in your active theme's snippets directory
  • Client Snippets - Located in a dedicated directory within wp-content

Practical source examples

Theme-based organization

Store snippets alongside your theme files for easy deployment and version control:

            add_filter('sleekByte/snippets/paths', function ($sources) {
      $sources[] = [
        'name' => 'Theme Snippets',
        'path' => get_template_directory() . '/snippets',
        'sort' => 10,
      ];

      // Child theme snippets (if using child theme)
      if (get_template_directory() !== get_stylesheet_directory()) {
        $sources[] = [
          'name' => 'Child Theme Snippets',
          'path' => get_stylesheet_directory() . '/snippets',
          'sort' => 5,
        ];
      }

      return $sources;
    });
  
                    
Copy

Plugin-based organization

Include snippets with your custom plugins:

            add_filter('sleekByte/snippets/paths', function ($sources) {
      $sources[] = [
        'name' => 'Site Plugin Snippets',
        'path' => WP_PLUGIN_DIR . '/my-site-plugin/snippets',
        'sort' => 20,
      ];

      $sources[] = [
        'name' => 'Must-Use Snippets',
        'path' => WPMU_PLUGIN_DIR . '/snippets',
        'sort' => 1,
      ];

      return $sources;
    });
  
                    
Copy

Environment-based organization

Organize snippets by development environment:

            add_filter('sleekByte/snippets/paths', function ($sources) {
      $environment = wp_get_environment_type();
      $upload_dir = wp_upload_dir();

      // Development-only snippets
      if ($environment === 'development') {
        $sources[] = [
          'name' => 'Development Tools',
          'path' => $upload_dir['basedir'] . '/sleek-byte-dev',
          'sort' => 5,
        ];
      }

      // Staging-specific snippets
      if ($environment === 'staging') {
        $sources[] = [
          'name' => 'Staging Features',
          'path' => $upload_dir['basedir'] . '/sleek-byte-staging',
          'sort' => 10,
        ];
      }

      // Production-only snippets
      if ($environment === 'production') {
        $sources[] = [
          'name' => 'Production Enhancements',
          'path' => $upload_dir['basedir'] . '/sleek-byte-prod',
          'sort' => 15,
        ];
      }

      return $sources;
    });
  
                    
Copy

Project-based organization

Organize snippets by client or project:

            add_filter('sleekByte/snippets/paths', function ($sources) {
      $upload_dir = wp_upload_dir();

      $sources[] = [
        'name' => 'Core Site Features',
        'path' => $upload_dir['basedir'] . '/sleek-byte-core',
        'sort' => 10,
      ];

      $sources[] = [
        'name' => 'E-commerce Features',
        'path' => $upload_dir['basedir'] . '/sleek-byte-ecommerce',
        'sort' => 20,
      ];

      $sources[] = [
        'name' => 'Marketing Tools',
        'path' => $upload_dir['basedir'] . '/sleek-byte-marketing',
        'sort' => 30,
      ];

      return $sources;
    });
  
                    
Copy