【问题标题】:How to add "Edit Shortcuts" icon to Wordpress customizer如何将“编辑快捷方式”图标添加到 Wordpress 定制器
【发布时间】:2016-12-07 06:57:58
【问题描述】:

如何将 WordPress 4.7 中的“编辑快捷方式”图标新功能添加到定制器。我想在我的主题定制器中的任何位置添加这个图标

【问题讨论】:

    标签: wordpress wordpress-4.7


    【解决方案1】:

    这些在定制器预览中称为“可见的编辑快捷方式”。你应该在这里阅读更多关于它的信息:

    https://make.wordpress.org/core/2016/11/10/visible-edit-shortcuts-in-the-customizer-preview/

    它是选择性刷新的扩展:

    $wp_customize->get_setting( 'blogname' )->transport        = 'postMessage';
    $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
    
    $wp_customize->selective_refresh->add_partial( 'blogname', array(
        'selector' => '.site-title a',
        'render_callback' => 'twentyfifteen_customize_partial_blogname',
    ) );
    $wp_customize->selective_refresh->add_partial( 'blogdescription', array(
        'selector' => '.site-description',
        'render_callback' => 'twentyfifteen_customize_partial_blogdescription',
    ) );
    

    渲染回调调用bloginfo( 'name' );bloginfo( 'description' );的地方

    https://make.wordpress.org/core/2016/02/16/selective-refresh-in-the-customizer/

    也可以查看官方Customizer documentation

    因此,基本上,如果您在自定义程序中进行了选择性刷新,这些将默认显示;)

    【讨论】:

    • 我有一个普通的文本控件,我想在不刷新定制器实时预览的情况下更改它。 ' $wp_customize->add_setting('copyright_text', array('default' => 'copyright', 'sanitize_callback' => 'sanitize_text_field') ); $wp_customize->add_control( 'copyright_text', array( 'label' => __( '页脚版权文本' ), 'section' => 'footer_section', ) );'
    • 如果我使用直接 javascript api 而不是 ajax 刷新会怎样?然后如何创建此编辑快捷方式?
    • 不确定,但我会离开定制器,因为计划是用完整的站点编辑和古腾堡替换它。所以我的建议是:专注于古腾堡、区块和完整的站点编辑,而不是将时间浪费在即将从 WP 核心中删除的内容上
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-28
    • 2012-02-15
    • 1970-01-01
    • 2019-07-14
    • 1970-01-01
    相关资源
    最近更新 更多