该插件允许在每篇文章/每页的基础上自定义JS和自定义CSS。https://wordpress.org/plugins/art-direction/
如果您发现它与您的WP安装不兼容,请查找其他允许自定义JS和CSS的插件。
如果您正在寻找更强健的解决方案,可以执行以下操作:
/* overlay-contact-form.css */
#overlayContactForm {
visibility: hidden;
position: absolute;
left: 0px;
top: 0px;
width:100%;
height:100%;
text-align:center;
z-index: 1000;
}
#overlayContactForm div {
width: 428px;
margin: 65px;
background-color: #fff;
border: 1px solid #000;
padding: 15px;
text-align: center;
height: 200px;
}
/* my-youtube.js */
// create youtube player
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player(\'player\', {
height: \'390\',
width: \'640\',
videoId: \'VhvUEhxL1DQ\',
playerVars: {
rel: 0
},
events: {
\'onReady\': onPlayerReady,
\'onStateChange\': onPlayerStateChange
}
});
}
// autoplay video
function onPlayerReady(event) {
event.target.playVideo();
}
// when video ends
function onPlayerStateChange(event) {
if (event.data === 0) {
// $(\'#lightbox-panel\').lightBox();
el = document.getElementById("overlayContactForm");
el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}
}
/* functions.php */
/**
* Proper way to enqueue scripts and styles
*/
function theme_name_scripts() {
wp_enqueue_style(\'style-name\', get_stylesheet_uri(). \'/css/overlay-contact-form.css\');
wp_enquue_script(\'youtube_api\', \'http://www.youtube.com/player_api\');
wp_enqueue_script(\'custom-script\', get_stylesheet_directory_uri().\'/js/my-youtube.js\', array(\'jquery\', \'youtube_api\', \'0.1.1\', true) );
}
add_action(\'wp_enqueue_scripts\', \'theme_name_scripts\');