I've been using the PHP code text format on my Drupal website and I have been encountering a frustrating issue with the Lexicon Module. I bet the answer is dead obvious, but I haven't been able to figure it out.

After I write my PHP code in the appropriate text format (php code) in the Lexicon modules "optional introductory text field", I hit save, and everything displays as it should on the page (great!). Problem is when I go back to make changes, "Full HTML" is selected as the text format and the PHP code has been replaced with HTML. When I then choose PHP Code as the text format, I can see some of the code I wrote (not all) but it's commented out with HTML comments. I know that my PHP code has been converted and replace with HTML not only in the input field because if I hit save again, then there is no PHP script saved - just garbled HTML gets displayed on the page.

Does anyone know how to use the PHP text format and make sure their PHP code actually sticks around if the content type is revisited? The reason I need to put PHP code in this field is because I want to do a language check of the current user and display text in either English or French.

1 Answer 1


I have been able to get a fix - but not an ideal one. I moved the PHP text format to be displayed as a first priority at admin/config/content/formats. Doing this preserves the PHP code after hitting save. The reason I say it's not ideal is because now PHP code will be displayed as the default format for making new pieces of content - fine for me, but I'm sure the client will wish they could get their WYSIWYG right away.

If anyone knows a way to target the display order of text formats for just one specific module, I'm sure that would be the solution.

  • Better Formats is a good option. It can set the allowed formats per field, as well as set the default order of formats. Aug 8, 2014 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.