Display code snippets that respect your spacing and tabs.
Example Block #1
/**
* An example of a piece of PHP code.
*
* @param string $text Text to test.
*
* @return string
*/
function string_function( $text ) {
$text = str_ireplace( 'test', 'text', $text );
return $text;
}
Code Example #1
<pre class="wp-block-code"><code></code></pre>
Block Example – with inline image
/**
* An example of a piece of PHP code.
*
* @param string $text Text to test.
*
* @return string
*/
function string_function( $text ) {
$text = str_ireplace( 'test', 'text', $text );
return $text;
}
Code Example – inline image
<pre class="wp-block-code"><code>
<img loading="lazy" width="300" height="300" class="wp-image-744" style="width: {width setting}px;" src="{src}" alt="{media library alt}" srcset="{srcset}" sizes="{sizes}" />
}</code></pre>
One response to “core/code”
The alt text on the media library item is not dynamically linked to the media library, but also can’t be edited within the code block; this makes it difficult to control the alt attribute value. Probably a bigger problem with the paragraph block, since realistically the code block shouldn’t support inline images at all.