Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 712
Anders Östman Avatar asked Feb 22 '17 08:02

Anders Östman


1 Answers

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'
    );
}   
like image 69
Lafif Astahdziq Avatar answered Sep 21 '22 12:09

Lafif Astahdziq