Create Menu on Theme Activation – WordPress

add_action(‘after_switch_theme’, ‘theme_activation_function’, 10 ,  2); function theme_activation_function ($oldname, $oldtheme = false) { /* Create header and footer menus */   $menus = array(     ‘Primary Menu’  => array(       ‘about-us’  => ‘About Us’,        ‘services’  => ‘Services’,        ‘templates-forms’  => ‘Templates & Forms’,        ‘clients’  => ‘Clients’,        ‘price-quote’  => ‘Price Quote’     ),   ‘Top Menu’ => array(     ‘home’ => ‘Home’,      ‘contact’ => ‘Contact’,      ‘sitemap’ => ‘Sitemap’   ),   ‘Footer Menu’ => array(     ‘terms-of-use’ => ‘Terms of Use’,      ‘privacy-policy’ => ‘Privacy Policy’   ) ); foreach($menus as $menuname => $menuitems) {   $menu_exists = wp_get_nav_menu_object($menuname);   // If it doesn’t exist, let’s create it.   if ( !$menu_exists) {     $menu_id = wp_create_nav_menu($menuname);     foreach($menuitems as $slug => $item) {       wp_update_nav_menu_item(       $menu_id, 0, array(             ‘menu-item-title’  => $item,             ‘menu-item-object’  => ‘page’,        … Continue reading Create Menu on Theme Activation – WordPress

Add A Security Question to the Register Form

Want to allow people to register on your site, but don’t want to be flooded with spam users? Try this: add_action( ‘register_form’, ‘add_register_field’ ); function add_register_field() { ?>     <p>         <label><?php _e(‘What is the name of the ship in the TV show Firefly?’) ?><br />         <input type=”text” name=”user_proof” id=”user_proof” class=”input” size=”25″ tabindex=”20″ /></label>     </p> <?php }… Continue reading Add A Security Question to the Register Form

Sort Query by post_in Parameter WordPress

Allows post queries to sort the results by the order specified in the post__in parameter. Just set the orderby parameter to post__in! add_filter( ‘posts_orderby’, ‘sort_query_by_post_in’, 10, 2 ); function sort_query_by_post_in( $sortby, $thequery ) { if ( !empty($thequery->query[‘post__in’]) && isset($thequery->query[‘orderby’]) && $thequery->query[‘orderby’] == ‘post__in’ ) $sortby = “find_in_set(ID, ‘” . implode( ‘,’, $thequery->query[‘post__in’] ) . “‘)”;… Continue reading Sort Query by post_in Parameter WordPress

Add custom javascript files to the wordpress site

Use wp_enqueue_script() in an init hook, or if in the admin only then in an admin_menu or admin_init hook. It might look something like this (which assumes you are calling from your theme’s functions.php file; note how I reference the stylesheet directory): <?php add_action(‘init’, ‘mysite_init’); function mysite_init() { $ss_url = get_bloginfo(‘stylesheet_directory’) wp_enqueue_script(‘mysite-scripts’,”$ss_url/js/mysite-scripts.js”); } That’s the basics. Pre-defined and Multiple Dependent Scripts But let’s say you… Continue reading Add custom javascript files to the wordpress site