I have created a content type in Drupal 8 and I added a field named "body". But I'm unable to use PHP code in this field.
How can I enable PHP in my "body" field?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI have created a content type in Drupal 8 and I added a field named "body". But I'm unable to use PHP code in this field.
How can I enable PHP in my "body" field?
Using PHP in your body field is considered bad practice. Read: What are the downsides of using PHP Filter code in blocks, nodes, views-args, etc?
Even in the module page it clearly says:
Warning
Enabling this module can cause security and performance issues as it allows users to execute PHP code on your site. There are better alternatives out there that do not expose such vulnerabilities on your site.
The proper way to add your PHP:
Furthermore, Twig has several filters and functions that you can make use of. Which in some cases, you don't even need to use PHP at all.
Install and configure PHP module.
The PHP Filter module adds a PHP filter to your site, for use with text formats.
Note: The PHP filter core module has been removed from core starting with version 8.x. Please check PHP filter overview