Archived topic
Can not display Code
10 replies · Started by Marius on May 10, 2020
Henlo,
I write an article, where i want to explain how to implement Braedcrumbs Navigation with Yoast Seo.
I write the php code in the code tags like so
<code><?php if ( function_exists('yoast_breadcrumb') && is_single() ) : ?>
<div class="grid-container yoast-breadcrumb">
<?php yoast_breadcrumb( '<p id="breadcrumbs">','</p>' ); ?>
</div>
<?php endif; ?></code>
But when I click on preview page i get this result:
','
' ); ?>
I use the Marketer Site, just to let you know
Use < pre > tag or you can use https://wordpress.org/plugins/code-syntax-block/ plugin
I don´t want to use a plugin just to show some code on my page. I thought that tht code tags are there to use. But they don´t work.
How can I make them work?
Try to insert code using < pre > .... </ pre > tag rather than using < code>
Hi there,
are you using the Block editor?
If so add the code directly to a Code Block.
That does not work. With the pre tag it gives me this:
','' ); ?>
No I am using classic text editor.
Is there eventually some css missing for displayin code?
WordPress strips out PHP from the editor.
The Code Block in the Block editor escapes the code so it can be displayed.
This article provides some different methods for doing what you need:
https://www.wpbeginner.com/wp-tutorials/how-to-easily-display-code-on-your-wordpress-site/
Thanks David,
I thought that the code tags in text editor are for such things. I will look into your suggestion.
Yeah most codes are fine - eg. HTML / CSS / JS to be output in a code block.
PHP is a server side language and WP will strip it for security reasons.