添加自定义Wordpress设置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了添加自定义Wordpress设置相关的知识,希望对你有一定的参考价值。
This is template for adding custom settings in Wordpress (using settings API).
/** * Wordpress add custom setting * Place this in functions.php file of your template. * */ function custom_settings() { ?> <form method="POST" action="options.php"> <?php settings_fields( 'custom-settings' ); //pass slug name of page, also referred //to in Settings API as option group name do_settings_sections( 'custom-settings' ); //pass slug name of page submit_button(); ?> </form> <?php } // add menu button add_action('admin_menu', 'plugin_admin_add_page'); function plugin_admin_add_page() { add_options_page('Custom Plugin Page', 'Custom Plugin Menu', 'manage_options', 'custom-settings', 'custom_settings'); } // This tells WordPress to call the function named "setup_theme_admin_menus" // when it's time to create the menu pages. // add_action("admin_menu", "setup_theme_admin_menus"); function eg_settings_api_init() { // Add the section to reading settings so we can add our // fields to it add_settings_section( 'eg_setting_section', 'Example settings section in reading', 'eg_setting_section_callback_function', 'custom-settings' ); // Add the field with the names and function to use for our new // settings, put it in our new section add_settings_field( 'eg_setting_name', 'Example setting Name', 'eg_setting_callback_function', 'custom-settings', 'eg_setting_section' ); // Register our setting so that $_POST handling is done for us and // our callback function just has to echo the <input> register_setting( 'custom-settings', 'eg_setting_name' ); } // eg_settings_api_init() add_action( 'admin_init', 'eg_settings_api_init' ); // ------------------------------------------------------------------ // Settings section callback function // ------------------------------------------------------------------ // // This function is needed if we added a new section. This function // will be run at the start of our section // function eg_setting_section_callback_function() { echo '<p>Intro text for our settings section</p>'; } // ------------------------------------------------------------------ // Callback function for our example setting // ------------------------------------------------------------------ // // creates a checkbox true/false option. Other types are surely possible // function eg_setting_callback_function() { echo '<input name="eg_setting_name" id="gv_thumbnails_insert_into_excerpt" type="checkbox" value="1" class="code" ' . checked( 1, get_option( 'eg_setting_name' ), false ) . ' /> Explanation text'; }
以上是关于添加自定义Wordpress设置的主要内容,如果未能解决你的问题,请参考以下文章
使用属性值为我的 wordpress 库中的每个图像添加自定义链接