Tag Archives: template files

How to Embed a Shortcode from a Plugin Directly into a Template File

I recently came across a great shortcode that I wanted to embed directly into a template, rather than use as a shortcode from within the admin area.

If you ever need to do this you can use the do_shortcode function, and pass any necessary parameters as you would need.

<?php echo do_shortcode('[shortcode with="parameters"]'); ?>

How to Get Post Type within WordPress Loop

There are some times when you want to test for the post type of an item in your loop. You may use this in your functions.php file for taking dynamic actions for custom post types, or you may need to use it directly in your template.

Either way, here is how you would save the post type as a variable:

get_post_type( $post->ID );

You can also use the function conditionally like this:

if( get_post_type( $post->ID ) == 'custom_post_type_name'):
     // Do custom code here

This function can be particularly helpful if you’re needing to work a lot with custom post types.