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’ );

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; } } ?>

Theme Demo in live Site

Drop this inside a .php file in in wp-content/mu-plugins: add_filter(‘template’, ‘check_for_theme_preview’); add_filter(‘stylesheet’, ‘check_for_theme_preview’); // if you want to display the theme selector // (this is wrong, you need a custom action in each of your themes, after <body>) add_action(‘wp_head’, ‘display_template_selector’); // checks for the “theme-preview” argument, and changes the template function check_for_theme_preview($template){ session_start(); if(isset($_SESSION[‘template’])) $template … Read more

How to hook into the quick edit action?

There are two flaws in the code that I can see. The first one is a bug in this code if($post->post_type != ‘product’) If no post exists, you get the following error Notice: Trying to get property of non-object… This can be fixed by first checking if a post isset if(isset($post) && $post->post_type != ‘product’) … Read more

Problem with tag

You can display a shortcode by using two (or three) square brackets at the open and close, e.g. [[[pdf href=”http://www.constitution.org/usdeclar.pdf”]Declaration of Independence[/pdf]]] In my experience, a standalone shortcode just needs two whereas one that wraps needs three on each end, even though I’ve seen it said that it should work just two in either case.