Wordpress php get_post_meta for post template

The name of the picture


Wordpress php get_post_meta for post template



I am using this little technique outlined here :



https://mekshq.com/include-javascriptonly-on-specific-wordpress-page-templates/



to limit the quantity of scripts etc. which load up on different pages on my site, by using the code:


$template_name = get_post_meta( $wp_query->post->ID, '_wp_page_template', true );
if($template_name == 'my-custom-template.php'){
//load my scripts
}



But I would like to use the same technique for POST templates, however '_wp_page_template' doesn't seem to recognize post templates, just page templates.



Is there some way I can change this to query if it is a post template instead? If not can I at least query if it is a post rather than a page, irrespective of template? That would probably be good enough, although querying the template would be preferable as it would give me more flexibility going forward.



I tried to look it up but sry, I am really not very strong in .php and most of the imfo I found is too complicated for me to rly follow.... like here there is a lot of info but it's like a week long lesson for me :/



https://codex.wordpress.org/Class_Reference/WP_Query



Thanks!!





Do you want to add that JS files only on template ?
– Sudharshan Nair
31 mins ago





for posts listing page please check with this : if(is_archive('post_type_name') ) and if you want to check for detail page then this : if(is_single('post_type_name') )
– raju_eww
22 mins ago


if(is_archive('post_type_name') )


if(is_single('post_type_name') )









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived