Forcing oembeds to top of post

you can create custom post meta which contain youtube url and then $yt=get_post_meta($post->ID,’youtube_url’,true); if( ” != $yt) echo $GLOBALS[‘wp_embed’]->autoembed( $yt ); Updated: If i’m getting correctly then your content contain youtube url any where in it and you want to show them at top regardless there position in content. jut paste this code in functions.php … Read more

Display only deepest category on a single post?

I come to this post as i was looking for the code. But the marked answer not working for me anymore. I have wrote a function to get the deepest level category assigned to a post. function post_deepest_level_cat($post_categories) { foreach ($post_categories as $category) { $cat_ids[] = $category->term_id; } $tree_args = array( ‘current_category’ => $cat_ids, ‘depth’ … Read more

Correct process for a new Page Template?

A page template defines the full rendered content displayed: header, footer, content – everything. So, at the very least, you’ll need to call get_header() and get_footer(), or manually add the header and footer code to the template. Also, I would recommend using a callback to enqueue your custom stylesheet. You can use the is_page_template() conditional … Read more

Remove navigation from header in custom page template

Use a conditional tag: Codex References: Function Reference (is_page) Function Reference (Conditional Tags) You can specify the landing page by Page ID, Page Title or Page Slug. Here is an example: <?php if ( !is_page( ‘landing-page’ ) ) { wp_nav_menu( array( ‘show_home’ => ‘Home’, ‘container’ => ‘false’, ‘theme_location’ => ‘main’) ); } endif; ?> It … Read more

How to add php to theme to show alt attributes

Try adding these codes to your theme’s function.php file: function isa_add_img_title( $attr, $attachment = null ) { $img_title = trim( strip_tags( $attachment->post_title ) ); $attr[‘title’] = $img_title; $attr[‘alt’] = $img_title; return $attr; } add_filter( ‘wp_get_attachment_image_attributes’,’isa_add_img_title’, 10, 2 );

Custom templates for posts like for pages: page-{id} vs single-{id}

A) Single Post Templates: single-{post-type}-{post-name}.php It’s informative to check out the get_single_template() function. There we find the following template possibilities: “single-{$object->post_type}-{$object->post_name}.php” “single-{$object->post_type}.php” “single.php” In WordPress 4.7 this part will be added: “single-{$object->post_type}-{$name_decoded}.php” So it looks like you forgot the {$object->post_type} part in the template’s name. Example: The single template name for the post with the … Read more