WordPress-使用子主题添加到Redux主题选项

无线g

我正在使用一个wordpress主题,它具有自己的框架,该框架基于我认为的redux框架。我正在使用子主题修改此主题。我想在后端添加到“主题选项”,并且在父主题的文件中找到了一个功能,该功能似乎正是我所需要的:

/*
 *
 * Custom function for filtering the sections array. Good for child themes to override or add to the sections.
 * Simply include this function in the child themes functions.php file.
 *
 * NOTE: the defined constansts for URLs, and directories will NOT be available at this point in a child theme,
 * so you must use get_template_directory_uri() if you want to use any of the built in icons
 *
 */
function add_another_section($sections){
    //$sections = array();
    $sections[] = array(
        'title' => __('A Section added by hook', 'swift-framework-admin'),
        'desc' => __('<p class="description">This is a section created by adding a filter to the sections array. Can be used by child themes to add/remove sections from the options.</p>', 'swift-framework-admin'),
        // Redux ships with the glyphicons free icon pack, included in the options folder.
        // Feel free to use them, add your own icons, or leave this blank for the default.
        'icon' => trailingslashit(get_template_directory_uri()) . 'options/img/icons/glyphicons_062_attach.png',
        // Leave this as a blank section, no options just some intro text set above.
        'fields' => array()
    );

    return $sections;
}
//add_filter('redux-opts-sections-twenty_eleven', 'add_another_section');

我已将此功能添加到子主题的functions.php中,并且未对add_filter进行注释。但是,这似乎不起作用,并且未添加任何新部分。

我在其他地方遇到过此讨论,该讨论表明需要更改函数的名称(我在此处遇到了相同的错误)。我已经做到了,但仍然行不通。

这是我的孩子主题functions.php中的内容

function add_another_section_bl($sections){
    $sections = array();
    $sections[] = array(
        'title' => __('A Section added by hook', 'swift-framework-admin'),
        'desc' => __('<p class="description">This is a section created by adding a filter to the sections array. Can be used by child themes to add/remove sections from the options.</p>', 'swift-framework-admin'),
        // Redux ships with the glyphicons free icon pack, included in the options folder.
        // Feel free to use them, add your own icons, or leave this blank for the default.
        'icon' => trailingslashit(get_template_directory_uri()) . 'options/img/icons/glyphicons_062_attach.png',
        // Leave this as a blank section, no options just some intro text set above.
        'fields' => array()
    );

    return $sections;
}
add_filter('redux-opts-sections-twenty_eleven', 'add_another_section_bl');

我不确定过滤器名称“ redux-opts-sections-twenty_eleven”是否需要编辑,因为它提到了二十一个主题。我尝试使用不同的主题名称(而不是二十一十一),但没有效果。

任何帮助将不胜感激!附带说明一下,通过将整个framwork文件夹复制到我的子主题中并在子主题的functions.php中定义框架的路径,我已经能够完成向主题选项中添加新选项的工作。我只是觉得应该有一种更流畅,更整洁的方法来实现这一目标,我认为该功能听起来很完美。

非常感谢。

多威

Redux Framework的首席开发人员在这里。仅当您使用Redux Framework 3.1+时,此解决方案才有效。如果您使用的是旧版本,请安装Redux Framework插件,它将覆盖主题中的版本。

首先转到当前的选项面板。打开一个JavaScript控制台(使用chrome或firefox),然后输入:redux.args.opt_name那会呼出一个名字。复制并粘贴到此函数中,替换OPT_NAME为已回显的名称:

function add_another_section_bl($sections){
    $sections = array(); // Delete this if you want to keep original sections!
    $sections[] = array(
        'title' => __('A Section added by hook', 'swift-framework-admin'),
        'desc' => __('<p class="description">This is a section created by adding a filter to the sections array. Can be used by child themes to add/remove sections from the options.</p>', 'swift-framework-admin'),
        // Redux ships with the glyphicons free icon pack, included in the options folder.
        // Feel free to use them, add your own icons, or leave this blank for the default.
        'icon' => trailingslashit(get_template_directory_uri()) . 'options/img/icons/glyphicons_062_attach.png',
        // Leave this as a blank section, no options just some intro text set above.
        'fields' => array()
    );

    return $sections;
}
// In this example OPT_NAME is the returned opt_name.
add_filter("redux/options/OPT_NAME/sections", 'add_another_section_bl');

祝你好运!

** 更新 **

同样,通过Redux API,您可以轻松地以这种方式添加新部分。

Redux::addSection(array(
        'title' => __('A Section added by hook', 'swift-framework-admin'),
        'desc' => __('<p class="description">This is a section created by adding a filter to the sections array. Can be used by child themes to add/remove sections from the options.</p>', 'swift-framework-admin'),
        // Redux ships with the glyphicons free icon pack, included in the options folder.
        // Feel free to use them, add your own icons, or leave this blank for the default.
        'icon' => trailingslashit(get_template_directory_uri()) . 'options/img/icons/glyphicons_062_attach.png',
        // Leave this as a blank section, no options just some intro text set above.
        'fields' => array()
    ))

我相信我们在Redux 3.2中发布了它,这使得使用我们的API稍微容易一些。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

WordPress添加主题选项

来自分类Dev

WordPress添加主题选项

来自分类Dev

在WordPress子主题中将do_shortcode添加到printf

来自分类Dev

将JavaScript函数添加到wordpress主题

来自分类Dev

将自定义Js添加到Wordpress主题

来自分类Dev

将JavaScript文件添加到WordPress主题

来自分类Dev

将小部件添加到 Wordpress Genesis 主题

来自分类Dev

Wordpress 子主题问题

来自分类Dev

将jQuery添加到Underscores(_s)WordPress主题的最佳方法是什么?

来自分类Dev

如何在Wordpress主题中将永久链接添加到WP_Query中

来自分类Dev

如何在Wordpress中将图像添加到自定义主题本身?

来自分类Dev

如何手动将小部件添加到WordPress主题?

来自分类Dev

在移动尺寸的宽度中如何将word菜单添加到wordpress 2014主题

来自分类Dev

将左侧边框添加到侧边栏(WordPress 24主题)

来自分类Dev

将target = _blank添加到JS文件中用于wordpress主题的一个链接

来自分类Dev

如何在Wordpress主题中将永久链接添加到WP_Query中

来自分类Dev

将背景图像添加到Jupiter 4 WordPress主题标头

来自分类Dev

自定义 WordPress 主题 - 菜单不会添加到导航

来自分类Dev

WordPress的功能主题选项格式

来自分类Dev

关于Wordpress中的主题选项

来自分类Dev

如何在Wordpress主题选项中使用Redux框架更改正文的背景图像?

来自分类Dev

WordPress子主题的命名约定

来自分类Dev

WordPress子主题的命名约定

来自分类Dev

WordPress子主题的特定角色

来自分类Dev

强调主题主题Wordpress

来自分类Dev

WordPress主题无法在线使用

来自分类Dev

在Wordpress子主题中使用$代替jQuery

来自分类Dev

WordPress,使用不同的主题:子域还是多站点?

来自分类Dev

WordPress我的主题选项设置未保存

Related 相关文章

热门标签

归档