Skip to content

Custom Render PHP

Custom Render PHP allows complete control over block output. Use this when you need custom PHP logic that Twig templates can’t handle.

Use custom render.php when you need:

  • Complex PHP logic
  • WordPress function integration
  • Custom database queries
  • External API calls
  • Performance-critical rendering
  1. In block editor, go to Settings (wbs section)
  2. Enable Custom Render Mode

render.php is only used when Custom Render Mode is enabled. Otherwise, blocks use Twig templates.

<?php
/**
* Custom render template for testimonial block
* $attributes contains all block attribute values
*/
$quote = isset($attributes['quote']) ? $attributes['quote'] : '';
$author = isset($attributes['author']) ? $attributes['author'] : '';
$style = isset($attributes['textColor']) ? 'color: ' . esc_attr($attributes['textColor']) : '';
?>
<div class="testimonial-block" style="<?php echo esc_attr($style); ?>">
<?php if ($quote) : ?>
<blockquote><?php echo wp_kses_post($quote); ?></blockquote>
<?php endif; ?>
<?php if ($author) : ?>
<cite><?php echo esc_html($author); ?></cite>
<?php endif; ?>
</div>
VariableDescription
$attributesAll block attribute values
$contextAdditional context data
$blockBlock data array
  • Always escape output with esc_html(), esc_attr(), wp_kses_post()
  • Sanitize inputs before using in queries
  • Use WordPress functions for data access
<?php
/**
* Block with dynamic post content
*/
$post_id = isset($attributes['postId']) ? intval($attributes['postId']) : 0;
$post = get_post($post_id);
if ($post) :
setup_postdata($post);
?>
<article class="featured-post">
<h2><?php the_title(); ?></h2>
<div class="content"><?php the_content(); ?></div>
</article>
<?php
wp_reset_postdata();
endif;

The Custom Render PHP is only available in WPBits Block Studio Pro. See Pro Features for more information.