How to Rearrange WPBakery Page Builder Categories? - wordpress

When I use vc_map() to add a new element to the content element list there is the category parameter to put the element in a certain tab.
If there are to many category tabs, VC will put some of them in a dropdown list on the right hand side. Is there a way to rearrange the order of all tabs?

There's a filter that can be hooked into to rearrange the order of the element categories: vc_add_element_categories.
For example:
add_filter( 'vc_add_element_categories', 'rearrange_element_categories', 10, 1 );
function rearrange_element_categories( $tabs ) {
// rearrange the tabs according to your needs
return $rearranged_tabs;
}

Don't know why someone would need this? Still you can arrange this as per your choice by jumping into plugin's code.
Con:
It will get reset, when in future you will be updating the plugin. And as per our understanding for WPBakery Page Builder plugin, you can't survive by without updating it.

Related

Hook menu to unset a link with conditions

I'm stuck with an issue on Drupal 7.
I have my main menu containing multiple links.
With the module menu_fields, I added a taxonomy to the menu links, and I want to alter this menu display based on the chosen one.
Problem is I do not know how to write my development.
I tested hook_menu(), hook_menu_alter(), hook_menu_alter_link() in my module but the dpm() I wrote in it never appears.
What I hope for is a hook with a param containing an array of the menu items.
Do you have an idea ?
Progress:
I manage to display something with hook_menu_alter() -I had to empty cache- but I can't find the main menu in the $items var.
Problem solved using mymodule_translated_menu_link_alter(&$item, $map).
You just have to do a if ($item['menu_name'] == 'main-menu') {} statement and add your code in it.
The best solution I can think of is to collect menu tree with menu_tree_all_data() function:
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_tree_all_data/7.x
and then to crawl tree structure (recursevly) and manually generate menu html.

WooCommerce: Adding Order Item Meta Data That's Hidden

I was under the impression that if you add an underscore to your meta_key, it would be hidden from the Admin and subsequently the Order Receipts, etc.
But, mine are showing? I don't understand what's going on...
meta_key: _testing_this, meta_value: asdasdasd
How do I added order item meta without it showing up?
If I am understanding correctly, to hide order metadata, you could use the existing hook Hidden Order Item Meta.
You could possibly add this to your functions.php or wherever you are storing your customizations:
add_filter( 'woocommerce_hidden_order_itemmeta', 'add_your_hidden_order_items' );
function add_your_hidden_order_items( $order_items ) {
$order_items[] = '_testing_this';
// any other entries you want to hide..
return $order_items;
}
I'm not sure this will remove the meta from the admin view. It may be worth while looking at this post about customizing the order meta box.
I hope this helps.
The answer is to serialize the data you want to be hidden.

Wordpress: Updating tags in large number of Posts

I have more than 2000 posts and each post contains almost 1000+ tags. Now i want to update all the posts with new additional tags in one go. Is there any simple way??
Regards-
From the dashboard:
Go to Posts -> All Posts
Beside Title there is a checkbox, check it and it will check all the boxes down the page.
Above the checkbox there is a dropdown list, select Edit and press Apply
You will see an input box called Tags, add the new tag in there
Next click the update button and those posts will now have the new tag.
I would recommend that you do this for one or two posts first to make sure it will work as you want and not break/mess anything up.
You have one more option, if some of the tags are similar for all the posts. You can post a piece of code in your function.php file and put the list of common tags there :
function my_tag_update () {
GLOBAL $post;
wp_set_post_tags( $post->ID, 'tag1, tag2, tag3, tag4', true );
}
add_action('publish_post', 'my_tag_update');
add_action('save_post', 'my_tag_update');
So, in this case when you create a new post or edit a post, these defined tags will add to it automatically.

Issue on CPT Custom Menu Position in WP

I have Two CPT as "Dress" and "Casual" and I would like to position them close to each other exactly after the "Dashboard" in the Menu.
I have this code in my custom post type for both:
'menu_position' => 2
how ever the result is displaying as:
the "Post" positions after the "Dress"! can you please let me know why this is happening and how I can keep all CPT after each other before the "Post".(I have 5 Custom Post Type)
Thanks
If Wordpress already has a menu item in the menu_position that you declare then it is moved to the next free position. Your issue is that Dashboard is in position 2 and then a separator is in position 4, so the second of your Post Types is moved to the next free position which is 6 (Posts is in position 5).
Note that Menu items are added in the order in which they are registered, so if they have the same menu_position, Post Types registered first will appear closer to the top of the menu.
However, you can move the default WP menu items if you so wish, thus achieving your desired display.
If you specify your menu_position as 6 and 7 for your custom Post Types, you can add this to move the separator to position 8 and Posts to position 9 -
add_action('admin_head', 'my_edit_admin_menu');
function my_edit_admin_menu(){
global $menu;
$menu[8] = $menu[4]; // Copy 'separator1' to a new menu location
unset($menu[4]); // Unset separator1 (from original position)
$menu[9] = $menu[5]; // Copy 'Posts' to a new menu location
unset($menu[5]); // Unset Posts (from original position)
ksort($menu); // Sort the menu
}
Note - the action admin_head is called after your custom Post Types are registered (using the init action). Because of this, you must ensure that your given menu_position values do clash with those of default menu items. If there is a clash, WP will move them before you get a chance to reorder the default items.
See the docs for menu_position in the Arguments section of the Function Reference for register_post_type() for the current WP default menu positions (although I believe that it is currently out of date for version 3.8). If you are ever unsure how the menu is organised, add this to the above code to output the full menu in the admin area -
echo '<pre>WP Admin Menu: '; print_r($menu); echo '</pre>';
FYI - I notice that you are using an image as the icon for you custom Post Types. As of WP 3.8, these were removed from the default admin dashboard in favour of DashIcons.
To make your Post Types look as pretty as the rest simply use the menu_icon argument, picking any of the icons from this page. To get the relevant name, click one and then look at the top of the page; the first icon is called dashicons-menu, for example.
if two menu items use the same position attribute, one of the items may be overwritten so that only one item displays! Risk of conflict can be reduced by using decimal instead of integer values, e.g. 2.3 instead of 2.
check here https://wordpress.stackexchange.com/questions/8779/placing-a-custom-post-type-menu-above-the-posts-menu-using-menu-position

Show secondary links in views only

I'm building a site in Drupal and I only want to show the secondary links on the
pages that use the Views I've created. I tried using the $secondary_links variable
in the views-view.tpl.php but the variable is null. How can I achieve this?
The secondary links are as mac correctly writes only available in page.tpl.php, but if I understand you correctly, the best solution is not getting the secondary links into your view.
With your theme, the secondary links, will most likely be printed out where they should, regardless of what is being displayed, be it your views, nodes, the front page etc. Views are displayed and everything else you render, is wrapped in the page template, that controls where menus are located, regions and other fun stuff.
Now, if you don't want to alter this, the location of the menus, their styling and this stuff, you shouldn't be printing the secondary menu in your views template, you shouldn't be doing anything with it at all.
The solution is simple
It's using something that mac mentioned but in a different way: preprocess function. These functions are used to in your template.php file, to add some logic to your variables. You can alter variables or remove them altogether. What I would do, would simply be to remove the primary links, by setting the value of $primary_links to an empty text string.
This would effectively remove the primary links, so only the secondary links are displayed. You could also display the secondary links as the primary, but this might cause confusing to your users. You just need to add some logic to control when this should happen and you are set.
Have you activated the secondary links from the theme settings? That would be:
http://example.com/admin/build/themes/settings/name_of_your_theme
I believe once you have activated the option, the variable will be populated.
EDIT: Thinking a second more, I would also comment that I am not sure if the primary and secondary links are passed to the views templates. I believe those are passed to the page.tpl.php file instead. If I am right, and for some reason you want to add that variable to those passed to the views template, you will have to use a preprocess function, like explained here.
EDIT #2: Indeed if you only need the secondary menu used in a specific views template, another approach would be to simply call menu_secondary_links() from within the template. This is not the most elegant solution ever, as it puts in a theming element something that should belong somewhere else, but it's up to you to make the call whether that menu in the views is a core functionality or a styling element.
HTH!
You can use the following code to show secondary menu on any view
function YourTheme_preprocess_views_view(&$vars)
{
$menu_sec = menu_navigation_links('menu-secondary');
$vars['custom_menu'] = theme('links__menu-secondary', array('links' => $menu_sec));
}
or you can even use other preprocess function depending upon your needs.
Further you can call it on .tpl.php file using:
<?php
$menu_sec = menu_navigation_links('menu-secondary');
print theme('links__menu-secondary',
array(
'links' => $menu_sec,
'attributes'=>array(
'class' => array('nav', 'nav-pills', 'p-f-subfilter'),
)
)
);
?>

Resources