Custom Field not showing code
-
Hello,
i would like to add a custom field to the general settings page of wordpress for inserting google tag manager code:
add_filter(‘admin_init’, ‘my_general_settings_register_fields’);
function my_general_settings_register_fields()
{
register_setting(‘general’, ‘google-tag-manager’, ‘esc_attr’);
add_settings_field(‘google-tag-manager’, ‘<label for=”google-tag-manager”>’.__(‘Google Tag Manager’ , ‘google-tag-manager’ ).'</label>’ , ‘my_general_settings_fields_html’, ‘general’);
}function my_general_settings_fields_html()
{
$value = get_option( ‘google-tag-manager’, ” );
echo ‘<input type=”text” id=”google-tag-manager” name=”google-tag-manager” value=”‘ . $value . ‘” />’;
}I use
<?php echo get_option(‘google-tag-manager’); ?>
in the template for displaying. it’s working, but on instering code into the textfield it returns:
& lt;!– Google Tag Manager –& gt;
so the script code isn’t shown correctly…”<” becomes “& lt;” for example.
Can you help me to solve this problem
- The topic ‘Custom Field not showing code’ is closed to new replies.