添加自定义wordpress设置

author author     2023-03-23     610

关键词:

This is template for adding custom settings in Wordpress (using settings API).
  1. /**
  2. * Wordpress add custom setting
  3. * Place this in functions.php file of your template.
  4. *
  5. */
  6. function custom_settings()
  7. ?>
  8. <form method="POST" action="options.php">
  9. <?php settings_fields( 'custom-settings' ); //pass slug name of page, also referred
  10. //to in Settings API as option group name
  11. do_settings_sections( 'custom-settings' ); //pass slug name of page
  12. submit_button();
  13. ?>
  14. </form>
  15. <?php
  16. }
  17.  
  18. // add menu button
  19. add_action('admin_menu', 'plugin_admin_add_page');
  20. function plugin_admin_add_page() {
  21. add_options_page('Custom Plugin Page', 'Custom Plugin Menu', 'manage_options', 'custom-settings', 'custom_settings');
  22. }
  23.  
  24.  
  25. // This tells WordPress to call the function named "setup_theme_admin_menus"
  26. // when it's time to create the menu pages.
  27. // add_action("admin_menu", "setup_theme_admin_menus");
  28.  
  29.  
  30.  
  31. function eg_settings_api_init() {
  32. // Add the section to reading settings so we can add our
  33. // fields to it
  34. add_settings_section(
  35. 'eg_setting_section',
  36. 'Example settings section in reading',
  37. 'eg_setting_section_callback_function',
  38. 'custom-settings'
  39. );
  40.  
  41. // Add the field with the names and function to use for our new
  42. // settings, put it in our new section
  43. add_settings_field(
  44. 'eg_setting_name',
  45. 'Example setting Name',
  46. 'eg_setting_callback_function',
  47. 'custom-settings',
  48. 'eg_setting_section'
  49. );
  50.  
  51. // Register our setting so that $_POST handling is done for us and
  52. // our callback function just has to echo the <input>
  53. register_setting( 'custom-settings', 'eg_setting_name' );
  54. } // eg_settings_api_init()
  55.  
  56. add_action( 'admin_init', 'eg_settings_api_init' );
  57.  
  58.  
  59. // ------------------------------------------------------------------
  60. // Settings section callback function
  61. // ------------------------------------------------------------------
  62. //
  63. // This function is needed if we added a new section. This function
  64. // will be run at the start of our section
  65. //
  66.  
  67. function eg_setting_section_callback_function() {
  68. echo '<p>Intro text for our settings section</p>';
  69. }
  70.  
  71. // ------------------------------------------------------------------
  72. // Callback function for our example setting
  73. // ------------------------------------------------------------------
  74. //
  75. // creates a checkbox true/false option. Other types are surely possible
  76. //
  77.  
  78. function eg_setting_callback_function() {
  79. 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';
  80. }

给wordpress后台侧栏菜单添加自定义字段的方法

我们在使用wordpress做网站的时候,难免有一些需要在后台设置侧栏菜单下添加自定义字段的情况。下面就简单说说一下,如何在后台设置侧栏菜单下添加自定义字段?在这里我们主要是使用wordpress的add_action(),下面通过自己的代... 查看详情

如何在 WordPress 中将类添加到自定义侧边栏

】如何在WordPress中将类添加到自定义侧边栏【英文标题】:HowToAddaClassToaCustomSidebarinWordPress【发布时间】:2017-06-2912:40:52【问题描述】:我刚刚学会了如何创建自定义WordPress主题。我想为我的侧边栏分配一个类以进行样式设置,... 查看详情

使用属性值为我的 wordpress 库中的每个图像添加自定义链接

】使用属性值为我的wordpress库中的每个图像添加自定义链接【英文标题】:Usinganattributevaluetoaddcustomlinksforeachimagesinmywordpresgallery【发布时间】:2021-12-2800:19:41【问题描述】:我在我的摄影网站上使用ElementorPro,我想为图库中的每... 查看详情

WordPress:本地主机上的自定义默认头像?

】WordPress:本地主机上的自定义默认头像?【英文标题】:WordPress:Customdefaultavataronlocalhost?【发布时间】:2012-12-1419:30:12【问题描述】:我正在尝试在functions.php中向WordPress添加自定义默认头像,但该图像未显示在“设置/讨论”... 查看详情

如何在自定义帖子中添加 wordpress 自定义部分

】如何在自定义帖子中添加wordpress自定义部分【英文标题】:Howtoaddwordpresscustomizesectionincustompost【发布时间】:2018-04-1015:40:32【问题描述】:如何创建该选项,请参阅thisimage在我的自定义主题上?我可以使用自定义帖子制作主题... 查看详情

如何在wordpress自定义中添加颜色选项

】如何在wordpress自定义中添加颜色选项【英文标题】:howtoaddcoloroptioninwordpresscustomize【发布时间】:2016-08-1515:41:00【问题描述】:我正在开发一个wordpress主题,我喜欢在自定义页面中添加一个颜色选项,以便管理员可以更改背景... 查看详情

WordPress仪表板上的自定义内容

】WordPress仪表板上的自定义内容【英文标题】:CustomContentonWordPressDashboard【发布时间】:2012-08-0101:43:21【问题描述】:我正在尝试找出将自定义内容添加到将在我的管理面板中定义的wordpress仪表板的最佳方法。所以基本上我会让... 查看详情

在 Wordpress 中为自定义帖子类型添加附加页面

】在Wordpress中为自定义帖子类型添加附加页面【英文标题】:AddingadditionalpagesforaCustomPostTypeinWordpress【发布时间】:2015-10-0417:40:09【问题描述】:我创建了一个名为“课程”的自定义帖子类型。Wordpress会自动为“课程”添加以下... 查看详情

我正在尝试在 wordpress 中添加自定义路由

】我正在尝试在wordpress中添加自定义路由【英文标题】:I\'mtryingtoaddcustomrouteinwordpress【发布时间】:2021-10-1420:05:12【问题描述】:我正在尝试在WordPress中添加自定义路由,但它返回“未找到与URL和请求方法匹配的路由。”这是... 查看详情

Wordpress 添加自定义角色以及删除默认角色

】Wordpress添加自定义角色以及删除默认角色【英文标题】:Wordpressaddcustomrolesaswellasremovedefaultroles【发布时间】:2012-01-1420:39:24【问题描述】:我需要自定义默认角色,因为我只需要3个角色-administrator,buyer,seller。然后我需要添加... 查看详情

Wordpress:自定义 wp_nav_menu 的输出,在嵌套 ul 之前添加一个 div

】Wordpress:自定义wp_nav_menu的输出,在嵌套ul之前添加一个div【英文标题】:Wordpress:Customisingoutputofwp_nav_menu,addingadivbeforenestedul【发布时间】:2011-04-1114:11:28【问题描述】:我正在构建一个使用大型下拉式菜单的网站,该菜单使用... 查看详情

WooCommerce:为特定页面添加使用 WordPress 自定义字段添加到购物车旁边的自定义按钮

】WooCommerce:为特定页面添加使用WordPress自定义字段添加到购物车旁边的自定义按钮【英文标题】:WooCommerce:AddforspecificpagesacustombuttonnexttoAddtoCartusingWordPressCustomFields【发布时间】:2020-04-0607:38:24【问题描述】:我正在寻找一种在... 查看详情

Wordpress - 如何通过其分类过滤添加的自定义帖子?

】Wordpress-如何通过其分类过滤添加的自定义帖子?【英文标题】:Wordpress-howtofiltertheaddedcustompostthroughitstaxonomy?【发布时间】:2022-01-1908:08:23【问题描述】:我在我的functions.php中添加了一个新的自定义帖子,如何通过其分类对现... 查看详情

如何在自定义插件中的 WordPress 自定义表单中添加验证

】如何在自定义插件中的WordPress自定义表单中添加验证【英文标题】:HowtoaddvalidationinWordPresscustomformincustomplugin【发布时间】:2019-03-0911:18:05【问题描述】:我已经制作了一个自定义表单并制作了一个自定义插件来发送电子邮件... 查看详情

如何在 wordpress 帖子区域中添加自定义 javascript?

】如何在wordpress帖子区域中添加自定义javascript?【英文标题】:Howtoaddcustomjavascriptinwordpresspostsarea?【发布时间】:2017-01-1220:57:35【问题描述】:我想在WordPress中添加一个JavaScript测验。我已经尝试过以HTML方式使用这种方法。但它... 查看详情

Wordpress 自定义 CSS 添加了两次?

】Wordpress自定义CSS添加了两次?【英文标题】:WordpressCustomCSSaddedtwice?【发布时间】:2016-07-2307:44:50【问题描述】:不是100%确定这个问题对于堆栈是否合法,但它不属于Meta并且确实涉及一些代码,我不认为它是主观的-应该有答... 查看详情

从 Wordpress 取消注册自定义帖子类型

】从Wordpress取消注册自定义帖子类型【英文标题】:UnregistercustomposttypefromWordpress【发布时间】:2016-08-1311:43:27【问题描述】:我正在尝试删除通过Wordpress中的不同主题设置的自定义帖子类型,现在所有这些帖子都分配给portfolio... 查看详情

如何将自定义 css 和 js 文件添加到 wordpress 的管理区域 [关闭]

】如何将自定义css和js文件添加到wordpress的管理区域[关闭]【英文标题】:Howdoiaddcustomcssandjsfilestoadminareaofwordpress[closed]【发布时间】:2013-09-0409:43:39【问题描述】:这个问题被问了太多次,并且有太多不同的问题,由于某种原因... 查看详情