WordPress Codesnippets

Programmatically create nav menu


$locations );

This code creates a navigation menu with a single item, ‘Home’, and assigns it to the primary location. It first checks if the menu exists, and if not, creates it using the wp_create_nav_menu() function. It then adds the ‘Home’ menu item using wp_update_nav_menu_item(), and assigns it to the primary location using get_theme_mod() and set_theme_mod().

Was this code snippet helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmatically save post

This code creates a WordPress post with the values of the ‘post_title’ and ‘post_content’ variables. It sets the post status to ‘publish’ and the author

Read More »

Create order programmatically

This code creates a new post in the WordPress database with post type ‘shop_order’, post title ‘Order #12345’, post status ‘wc-processing’, and ping status ‘closed’.

Read More »