admin管理员组文章数量:1326632
How to make wp_enqueue_style and wp_enqueue_script work only on custom post type
I have install plugin on my wordpress that creat custom post type which is "http://localhost/wordpress/manga" and i have other custom post type like "http://localhost/wordpress/anime" so i only want to css work on manga not anime or in the front page
this is the code: wp_enqueue_style( 'wp-manga-plugin-css', WP_MANGA_URI . 'assets/css/style.css' );
How to make wp_enqueue_style and wp_enqueue_script work only on custom post type
I have install plugin on my wordpress that creat custom post type which is "http://localhost/wordpress/manga" and i have other custom post type like "http://localhost/wordpress/anime" so i only want to css work on manga not anime or in the front page
this is the code: wp_enqueue_style( 'wp-manga-plugin-css', WP_MANGA_URI . 'assets/css/style.css' );
Share Improve this question asked Aug 4, 2020 at 18:21 التقنية techالتقنية tech 133 bronze badges2 Answers
Reset to default 1You can use conditionals:
<?php
add_action( 'wp_enqueue_scripts', 'wpse_enqueues' );
function wpse_enqueues() {
// Only enqueue on specified single CPTs
if( is_singular( array( 'anime', 'manga' ) ) ) {
wp_enqueue_style( 'wp-manga-plugin-css', WP_MANGA_URI . 'assets/css/style.css' );
}
}
?>
If you need the CSS on archives as well, that's another condition:
if( is_singular( array( 'anime', 'manga' ) ) || is_post_type_archive( array( 'anime, 'manga' ) ) ) {
wp_enqueue_style( 'wp-manga-plugin-css', WP_MANGA_URI . 'assets/css/style.css'
}
Perhaps you're looking for is_singular
, which you could put in e.g. your theme or functions.php to test for your CPT like:
if (is_singular('anime')) {
wp_enqueue_style( ... ) ;
}
本文标签: pluginsHow to make wpenqueuestyle and wpenqueuescript work only on custom post type
版权声明:本文标题:plugins - How to make wp_enqueue_style and wp_enqueue_script work only on custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742210759a2433665.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论