پرش به محتویات

"Filter: bricks/placeholder_image"

فیلتر bricks/placeholder_image به شما این امکان را می‌دهد که تصویر مکان‌نمای پیش‌فرض مورد استفاده در Bricks را لغو کنید. این می‌تواند زمانی مفید باشد که می‌خواهید یک مکان نگهدار سفارشی برای عناصر در هنگام وارد کردن الگو یا چسباندن عناصر از وب سایت دیگری نمایش دهید. (@since 2.0)

پارامترها

  • $image (string) – The default placeholder image path or URL.
  • $is_svg (bool) – Whether the placeholder should be an SVG. Leave as is.
  • $format (string) – Can be 'url' or 'path' depending on the context Bricks needs it for. Leave as is.
add_filter( 'bricks/placeholder_image', function( $image, $is_svg, $format ) {
  // Custom placeholder images (SVG and non-SVG file required)
  // SVG file: /uploads/2025/04/my-placeholder.svg
  // Non-SVG file: /uploads/2025/04/my-placeholder-img.png
  $relative_path = $is_svg ? '2025/04/my-placeholder.svg' : '2025/04/my-placeholder-img.png';
  $upload_dir    = wp_get_upload_dir();

  if ( $format === 'path' ) {
    // Return absolute path to the image
    $image = $upload_dir['basedir'] . '/' . $relative_path;
  } else {
    // Return full URL to the image
    $image = $upload_dir['baseurl'] . '/' . $relative_path;
  }

  return $image;
}, 10, 3 );