Wp Undefined Function Add_Settings_Section

I'm trying to add sections and fields to a new settings page i WordPress. But I get the response "Call to undefined function add_settings_section()...". Does anybody know why that is? This is the code in question: add_settings_section( 'ac_div', 'Inställningar', 'ac_section_text', 'Anders-counter' );

add_settings_field(
    'diven',
    'För in mätarställningen här',
    'ac_add_field',
    'Anders-counter',
    'ac_div');

Thankful for help. Anders

1 Answer

add_settings_field function located under wp-admin/includes/template.php

you can load that file before calling add_settings_field, or simply add your code under admin_init hook

add_action('admin_init', 'your_function');
function your_function(){
    add_settings_field(
        'diven',
        'För in mätarställningen här',
        'ac_add_field',
        'Anders-counter',
        'ac_div'
    );
}   

Your Answer

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

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest