1

I am working on a plugin and on the settings page I have 2 settings and I want to show Only one setting "backgroundColor" so how should i do that?

This is the code:

<form action="options.php" method="post">
<?php
    settings_errors();

    settings_fields( 'bg_color' );  **<<< I want only background settings to show how i can do it correclty?**

    do_settings_sections( 'plugin-style' );

    submit_button( __('Save settings', 'trans') );
                                        ?>
</form>


        /* Add Settings Field for Background Color */
    add_settings_field(
        'background-color',
        __('Background Color', 'trans'),
        'plugin_background_color_ca',
        'plugin-style',
        'style-settings-section-2',
        array(
            'name'      => 'bg_color',
            'id'        => 'style-settings-background-color',
            'class'     => 'style-settings-background-color',
            'options'   => $style_opts,
        )
    );

    /* Add Settings Field for Font Size */
    add_settings_field(
        'st-search-font-size',
        __('Font Size', 'trans'),
        'plugin_font_size_ca',
        'plugin-style',
        'style-settings-section-2',
        array(
            'name'      => 'font_size',
            'id'        => 'style-settings-font-size',
            'class'     => 'style-settings-font-size',
            'options'   => $style_opts,
        )
    );

N

3
  • 1
    settings_fields is just for the nonces and hidden inputs, it doesn't display the settings on the page. What's the problem that requires you to only show this? Are you trying to implement tabs or accordions? I'm not sure why you would register a section, put 2 settings in it, but only show 1
    – Tom J Nowell
    Apr 29 at 16:02
  • @TomJNowell yes i'm trying to show only one, not all settings, i can do it with javascript but i'm askin if there away to do it with php. Apr 29 at 16:08
  • 1
    can you explain why though? The context is important and might impact the solution significantly, you shouldn't need to do this but without knowing why you want it it's very difficult to say what you need to do ( or it may be a perfectly reasonable reason, in which case humour me anyway )
    – Tom J Nowell
    Apr 29 at 16:59

0

Your Answer

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

Browse other questions tagged or ask your own question.