• 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

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    WP tends to pass every text field through htmlentities() whether you want it or not. There’s probably some clever way to prevent this, but I’d take the easy way out and just undo the entity conversion after get_option() with either str_replace() or html_entity_decode().

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Field not showing code’ is closed to new replies.