How do I grab specific posts (by post id) and display the title, featured image, and excerpt?

I have not tested this but based on your question, this should get you on track: <?php $id = 4; // The Page or post ID $page_data = get_post( $id ); $title = $page_data->post_title; $content = $page_data->post_content; $excerpt = substr($content, 0, 155); $featured_image = wp_get_attachment_url( get_post_thumbnail_id($id, ‘thumbnail’) ); ?> <div class=”post”> <h1><?php echo $title; ?></h1> … Read more

How to hook into permalink when publishing-saving post?

Finally, I found my answer on my own. //add our action add_action( ‘save_post’, ‘my_save_post’, 11, 2 ); function my_save_post($post_id, $post){ //if it is just a revision don’t worry about it if (wp_is_post_revision($post_id)) return false; //if the post is an auto-draft we don’t want to do anything either if($post->post_status != ‘auto-draft’ ){ // unhook this function … Read more

Add my own function to existing WooCommerce hook

storefront_single_post hook pertains only to single posts and not products although products are considered posts of type ‘product’ This is the hook you need: add_action( ‘woocommerce_single_product_summary’, ‘storefront_post_header_categories’, 6 ); function storefront_post_header_categories() { echo “code to display categories here”; } You will find it in plugins/woocommerce/content-single-product.php: /** * woocommerce_single_product_summary hook * * @hooked woocommerce_template_single_title – 5 … Read more

Getting my head round WordPress filter

You are using the filter wrongly, that is why you might not get the desired result. Lets first look at the template_include filter which you can check out in wp-includes/template-loader.php (current version 4.3.1) 44 if ( defined(‘WP_USE_THEMES’) && WP_USE_THEMES ) : 45 $template = false; 46 if ( is_404() && $template = get_404_template() ) : … Read more

Remove and restore one shortcode

Another old unanswered question. Hopefully useful to someone in the future. WordPress stores shortcode tags and callbacks in the $shortcode_tags. This is how I’d do it. function my_the_content( $content ) { global $shortcode_tags; $tag= ‘some_shortcode’; //* Make sure it’s actually a valid shortcode if( ! isset( $shortcode_tags[ $tag ] ) ) { return $content; } … Read more

Add a header before fields added with the attachment_fields_to_edit() filter

I’ve found out that you can use the tr attribute for creating entire rows: function my_attachment_fields_to_edit( $form_fields, $post ) { $form_fields[‘attachment-header’][‘tr’] = ‘ <tr> <td colspan=”2″> <h2>My title</h2> </td> </tr>’; $form_fields[‘attachment-url’] = array( ‘label’ => __( ‘URL’, ‘plugin’ ), ‘input’ => ‘text’, ‘value’ => get_post_meta( $post->ID, ‘_attachment_url’, true ) ); $form_fields[‘attachment-width’] = array( ‘label’ => … Read more