[Resolved] Can not display Code

Home Forums Support Can not display Code

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1277486
    Sonja

    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

    #1277492
    Suraj Katwal

    Use < pre > tag or you can use https://wordpress.org/plugins/code-syntax-block/ plugin

    SEO, WordPress Optimization, Blogging Tutorials.
    GeneratePress Tutorial: https://www.wplogout.com

    #1277508
    Sonja

    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?

    #1277524
    Suraj Katwal

    Try to insert code using < pre > …. </ pre > tag rather than using < code>

    SEO, WordPress Optimization, Blogging Tutorials.
    GeneratePress Tutorial: https://www.wplogout.com

    #1277657
    David
    Staff
    Customer Support

    Hi there,

    are you using the Block editor?
    If so add the code directly to a Code Block.

    #1277677
    Sonja

    That does not work. With the pre tag it gives me this:

    ','' ); ?>

    #1277680
    Sonja

    No I am using classic text editor.

    #1277748
    Sonja

    Is there eventually some css missing for displayin code?

    #1277766
    David
    Staff
    Customer Support

    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/

    #1277936
    Sonja

    Thanks David,

    I thought that the code tags in text editor are for such things. I will look into your suggestion.

    #1277948
    David
    Staff
    Customer Support

    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.

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.