WordPress.org

Forums

[resolved] Weird bug: WordPress auto convert PHP to HTML code (5 posts)

  1. Tien Nguyen
    Member
    Posted 1 year ago #

    Dear all,

    I just install a new Centos server with Ngnix and php-fpm.

    Now, I am develop a template with my site at: bloggeritems.com
    But a weird error is when I code like below:

    <div class="blog-info">
    				<?php $fname = 'Blogger Items'; ?>
    
    				<?php if ( is_archive() ) : ?>
    					<h1 class="site-title"><?echo $fname;?></h1>
    				<?php else : ?>
    					<h2 class="site-title"><?echo $fname?></h2>
    				<?php endif; ?>
    
    				<p class="site-description"><?php bloginfo( 'description' ); ?></p>
    			</div>

    The output result will like below:

    <div class="blog-info">
    
    									<h2 class="site-title"><!--?echo $fname?--></h2>
    
    				<p class="site-description">Blogger and Blogspot Organization created amazing templates, widget, guide, tips, discussions and all free for you.</p>
    			</div>

    Mean <?echo $fname;?> in PHP will become <!--?echo $fname?--> in HTML
    This is WP bug or I am a noob?

    Appreciate all helps.

    Best regards,
    Tien Nguyen

  2. Ken Mackenzie
    Member
    Posted 1 year ago #

    Looks like you probably dont have php shortcodes enabled so that php code that begins with "<?" is not recognised and therefore the code not executed. For example <? Echo $fname; ?>...

    In your php.ini file on your server, search for and then make sure the following line is set as follows, then restart your web server software:

    short_open_tag=On

    That should fix it.

    Cheers,

    Ken

  3. Ken Mackenzie
    Member
    Posted 1 year ago #

    Or else , change all instances of <? to <?php

    (:-)

  4. Tien Nguyen
    Member
    Posted 1 year ago #

    Dear Ken,

    Thank for your suggestion, it's working now. I found NGNIX can not process <?, you must use <?php.

    Best regards,
    Tien

  5. davewatts
    Member
    Posted 10 months ago #

    you could try this php/js/smarty online formatting tool, if you get stuck

    https://www.ejectamenta.com/online-apps/code2html.html

Topic Closed

This topic has been closed to new replies.

About this Topic