I am trying to use some code that is stored as a settings option in WordPress. When I try to use the following code below however, it show up as plain text instead of executing. The option I have created contains the following PHP code:

echo get_option('profiles_templates_html'. $template .'');
| improve this question | | | | |
  • 3
    You are trying to execute the PHP? – s_ha_dum Mar 31 '14 at 15:25
  • 1
    Storing PHP code in the DB is so, SO wrong. Whatever you're trying to do, don't do it that way. Please. – Dan Mar 31 '14 at 15:50
  • then how should I do it. I am trying to have a few different templates that I can use. – venn414 Mar 31 '14 at 16:34
  • Have you wrapped it in <?php ... ?>? – TheDeadMedic Mar 31 '14 at 16:44
  • as in in the option.. then yes. please help. – venn414 Mar 31 '14 at 17:48

If you really want to execute code stored in a database, a quick google search reveals that you can use the eval() function to do just that. However, many people do say that Eval is Evil...

Instead of storing the entire PHP code of an option in the database, try storing a simple boolean flag for your option and then test whether to get your template's option data from there:


// Somewhere else in your code, store the settings option upon saving settings
update_option( 'my_setting_for_template', 1 );

// Test if get_option returns 1 from the database
if( get_option( 'my_setting_for_template' ) === 1 )
    echo get_option('profiles_templates_html'. $template .'');



| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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