链接到特定的“定制程序”部分


Answers:


25

正如您已经发现的那样,指向定制器的链接始终以开头/wp-admin/customize.php

追加以在定制器中签出您的部分。这两个参数(和)都在钩子中注册:?autofocus[section] =section_namesectionsection_namecustomize_register

$wp_customize->add_section

如果找不到该挂钩,请检查定制器的HTML标记以获取更多信息。这两个参数都包含在列表中:

<li id="accordion-section-title_tagline" class="accordion-section control-section control-section-default">

总的来说,您的链接可能看起来像这样:

admin_url( '/customize.php?autofocus[section]=section_name' );

这些是二十个二十个WordPress主题中默认定制程序部分的链接:

  • 网站身份: /customize.php?autofocus[section]=title_tagline
  • 颜色: /customize.php?autofocus[section]=colors
  • 主题选项: /customize.php?autofocus[section]=options
  • 封面模板: /customize.php?autofocus[section]=cover_template_options
  • 背景图片: /customize.php?autofocus[section]=background_image
  • 菜单: /customize.php?autofocus[panel]=nav_menus
  • 小部件: /customize.php?autofocus[panel]=widgets
  • 主页设置: /customize.php?autofocus[section]=static_front_page
  • 其他CSS: /customize.php?autofocus[section]=custom_css

从哪里去?

我经常发现自己需要WordPress管理菜单中“ 外观”中的菜单项。因此,这也许对您也有帮助:

add_action( 'admin_menu', 'wpse_custom_submenu_page' );
function wpse_custom_submenu_page() {
  add_submenu_page(
    'themes.php',
        __( 'Page title', 'textdomain' ),
        __( 'Menu title', 'textdomain' ),
        'manage_options',
        '/customize.php?autofocus[section]=section_name'
    );
}

2
这是一个很好的概述+1。
birgire

1
您还可以通过附加多个autofocus参数来深度链接到嵌套部分。例如,打开WooCommerce的“产品目录”部分。 customize.php?autofocus[panel]=woocommerce&autofocus[section]=woocommerce_product_catalog
Darren Cooney
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.