Default or Preset Content for Custom Post Types

Use the second parameter $post and check $post->post_type alongside a switch, it’s easier and nicer to work with than several if else if else, etc.. add_filter( ‘default_content’, ‘my_editor_content’, 10, 2 ); function my_editor_content( $content, $post ) { switch( $post->post_type ) { case ‘sources’: $content=”your content”; break; case ‘stories’: $content=”your content”; break; case ‘pictures’: $content=”your content”; … Read more

wp_mail not running inside Cron

This one is a bit of a puzzler. I was originally going to say you need to determine if there’s something wrong after the mail is sent since you’re getting the hit in the next operation. But then I re-read it and caught the part about the email being received when it’s run manually. What … Read more

How to remove the embed_footer?

The comments button and the share button are generated in two separate default actions, so you have to remove them both: remove_action( ’embed_content_meta’, ‘print_embed_comments_button’ ); remove_action( ’embed_content_meta’, ‘print_embed_sharing_button’ );

Removing the default sidebar from admin panel

If you mean the default WordPress Widgets, you would add this to the functions.php file: <?php // unregister all default WP Widgets function unregister_default_wp_widgets() { unregister_widget(‘WP_Widget_Pages’); unregister_widget(‘WP_Widget_Calendar’); unregister_widget(‘WP_Widget_Archives’); unregister_widget(‘WP_Widget_Links’); unregister_widget(‘WP_Widget_Meta’); unregister_widget(‘WP_Widget_Search’); unregister_widget(‘WP_Widget_Text’); unregister_widget(‘WP_Widget_Categories’); unregister_widget(‘WP_Widget_Recent_Posts’); unregister_widget(‘WP_Widget_Recent_Comments’); unregister_widget(‘WP_Widget_RSS’); unregister_widget(‘WP_Widget_Tag_Cloud’); unregister_widget(‘WP_Nav_Menu_Widget’); } add_action(‘widgets_init’, ‘unregister_default_wp_widgets’, 1); ?> EDIT: register_sidebar(array(‘name’=>’sidebar2’, ‘before_widget’ => ‘<ul><li>’, ‘after_widget’ => “</li></ul>”, ‘before_title’ => ‘<h2 class=”widgettitle”>’, … Read more

simple wp_insert_post example

// Create post object $my_post = array(); $my_post[‘post_title’] = ‘My post’; $my_post[‘post_content’] = ‘This is my post.’; $my_post[‘post_status’] = ‘publish’; $my_post[‘post_author’] = 1; $my_post[‘post_category’] = array(0); // Insert the post into the database wp_insert_post( $my_post );” This works fine. You code is correct, but it is an problem in the form to send the $_POST … Read more

WooCommerce – Customer Order History Pagination

I have added pagination in order history page and it is working. Replace below code above loop $my_orders_columns = apply_filters( ‘woocommerce_my_account_my_orders_columns’, array( ‘order-number’ => __( ‘ID’, ‘woocommerce’ ), ‘order-date’ => __( ‘Date’, ‘woocommerce’ ), ‘order-total’ => __( ‘Packages’, ‘woocommerce’ ), ‘order-total’ => __( ‘Price’, ‘woocommerce’ ), ‘order-status’ => __( ‘Status’, ‘woocommerce’ ), ‘order-actions’ => ‘&nbsp;’, … Read more

Generate

You can use wp_head action to add something to head section. You can change the output according your needs. <?php add_action(‘wp_head’,’add_meta_des’); function add_meta_des() { if(is_single()) { global $wp_query; $post = $wp_query->post; $page_id = $post->ID; $page_object = get_page( $page_id ); $content = wp_trim_words($page_object->post_content,30); $output=”<meta name=”description” content=””.get_the_title().”–“.$content.””/>”; echo $output; } } ?>