admin管理员组文章数量:1390878
A few basic questions to accelerate my wordpress plugin development start. I'd like to develop a wordpress plugin that adds some javascript and css to a specific page. What filters or actions should be used? How to restrict execution of a plugin to a single (known) page? How can a plugin add some content to a page?
A few basic questions to accelerate my wordpress plugin development start. I'd like to develop a wordpress plugin that adds some javascript and css to a specific page. What filters or actions should be used? How to restrict execution of a plugin to a single (known) page? How can a plugin add some content to a page?
Share Improve this question asked Jan 30, 2012 at 12:57 Davos SeaworthDavos Seaworth 1952 gold badges4 silver badges8 bronze badges2 Answers
Reset to default 2WordPress has a built-in function called wp_enqueue_script() which will allow a certain piece of JavaScript to be included in a page. If you'd just like to see that script on a particular page, you can conditionally call it from the theme file. For example:
<?php if (is_page('home')) {
wp_register_script('custom_script', get_template_directory_uri() .
'/js/custom_script.js');
wp_enqueue_script('custom_script');
} ?>
You can do something similar with wp_register_style() and wp_enqueue_style() to include the CSS as well.
Take a look at Page Specific CSS/JS plugin source code -- This simple plugin allows you include a separate stylesheet and/or javascript file for any page on your site.
本文标签: cssHow to execute a plugin on a single page only
版权声明:本文标题:css - How to execute a plugin on a single page only? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744752320a2623253.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论