• Resolved billysgtr

    (@billysgtr)


    Hi, I am using Code Editor type in PHP mode.
    I add php code in the field but it is wrapped with html comments <!– ->

    Is this normal for security reasons? Or is it possible to add php code in the field?

    Thanks

    WP Version 5.9.1
    ACF Pro Version 5.12
    Advanced Custom Fields: Extended Version 0.8.8.7

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    Yes, it is normal if you entered a value such as:

    <?php echo 'Hello World'; ?>
    

    WordPress will automatically add comments when using get_field() or the native get_post_meta() function, for security reasons. I wouldn’t recommend to use that Field to render PHP code. But if you really want to do it you could enter the following value:

    echo 'Hello World';
    

    And then eval() (see documentation) the code on the front-end using the following code:

    <?php eval(get_field('my_code')); ?>
    

    Please note that using this method is very dangerous, I wouldn’t recommend using it unless you really know what you’re doing.

    Hope it helps!

    Have a nice day!

    Regards.

    Thread Starter billysgtr

    (@billysgtr)

    Hi,
    Yes, I understand.

    THanks for the reply.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    You’re welcome!

    Have a nice day!

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘php code wrapped with html comments’ is closed to new replies.