admin管理员组文章数量:1024603
I'm using the snippet from Open Admin bar "Visit site" in a new window which works perfectly on the node I specify.
I need to adapt this to include all of the sub-nodes, which are dynamically created, but follow this logic:
node
node_1
node_1_view
node_1_another
node_1_andanother
node_2
node_2_view
etc
node_3
etc
This gets additions following the same sequence.
How can I modify the code to set the target for all of these node?
I'm using the snippet from Open Admin bar "Visit site" in a new window which works perfectly on the node I specify.
I need to adapt this to include all of the sub-nodes, which are dynamically created, but follow this logic:
node
node_1
node_1_view
node_1_another
node_1_andanother
node_2
node_2_view
etc
node_3
etc
This gets additions following the same sequence.
How can I modify the code to set the target for all of these node?
Share Improve this question asked Apr 15, 2019 at 23:49 Jarod ThorntonJarod Thornton 6384 silver badges18 bronze badges 1- What do you mean by nodes? Posts? Menu items? – norman.lol Commented Apr 16, 2019 at 7:46
1 Answer
Reset to default 0Perhaps you could use $wp_admin_bar->get_nodes();
to get all toolbar nodes, then loop them through and modify the right nodes as needed. Something along these lines,
add_action( 'admin_bar_menu', 'customize_my_wp_admin_bar', 80 );
function customize_my_wp_admin_bar( $wp_admin_bar ) {
$all_toolbar_nodes = $wp_admin_bar->get_nodes();
if ( ! $all_toolbar_nodes ) {
return;
}
foreach ( $all_toolbar_nodes as $node ) {
// Skip nodes you don't want to edit
if ( ! $some_logic ) {
continue;
}
//Change target
$node->meta['target'] = '_blank';
//Update Node.
$wp_admin_bar->add_node($node);
}
}
I can't remember what properties $node
has, but I guess there's some sort of parent
property that you can use in the if
statement to skip the wrong ones.
I'm using the snippet from Open Admin bar "Visit site" in a new window which works perfectly on the node I specify.
I need to adapt this to include all of the sub-nodes, which are dynamically created, but follow this logic:
node
node_1
node_1_view
node_1_another
node_1_andanother
node_2
node_2_view
etc
node_3
etc
This gets additions following the same sequence.
How can I modify the code to set the target for all of these node?
I'm using the snippet from Open Admin bar "Visit site" in a new window which works perfectly on the node I specify.
I need to adapt this to include all of the sub-nodes, which are dynamically created, but follow this logic:
node
node_1
node_1_view
node_1_another
node_1_andanother
node_2
node_2_view
etc
node_3
etc
This gets additions following the same sequence.
How can I modify the code to set the target for all of these node?
Share Improve this question asked Apr 15, 2019 at 23:49 Jarod ThorntonJarod Thornton 6384 silver badges18 bronze badges 1- What do you mean by nodes? Posts? Menu items? – norman.lol Commented Apr 16, 2019 at 7:46
1 Answer
Reset to default 0Perhaps you could use $wp_admin_bar->get_nodes();
to get all toolbar nodes, then loop them through and modify the right nodes as needed. Something along these lines,
add_action( 'admin_bar_menu', 'customize_my_wp_admin_bar', 80 );
function customize_my_wp_admin_bar( $wp_admin_bar ) {
$all_toolbar_nodes = $wp_admin_bar->get_nodes();
if ( ! $all_toolbar_nodes ) {
return;
}
foreach ( $all_toolbar_nodes as $node ) {
// Skip nodes you don't want to edit
if ( ! $some_logic ) {
continue;
}
//Change target
$node->meta['target'] = '_blank';
//Update Node.
$wp_admin_bar->add_node($node);
}
}
I can't remember what properties $node
has, but I guess there's some sort of parent
property that you can use in the if
statement to skip the wrong ones.
本文标签: Set anchor target for admin bar nodes
版权声明:本文标题:Set anchor target for admin bar nodes 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745583884a2157467.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论