Подключение скрипта

BITH0VEN

Новичок
Регистрация
14.02.2013
Сообщения
2
Доброго времени суток!
Ребята помогите пожалуйста! Уже второй день е...., пытаюсь подключить скрипт в WP правельным способом.
Мне нужно научиться писать ПЛАГИНЫ на WP, и я пытаюсь подключать свой скрипт именно из ПЛАГИНА. Но все что я гуглю описывает подключение из темы.
И так:
Есть папочка в wp-content/plugins/my-plugin, там файлик my-plugin.php (он работает). Его код:
Код:
<?php
/*
Plugin Name: My-Plugin
Description: Это супер плагин.
Version: 1.0
Author: Михаил Щедраков

Copyright 1013 Щедраков Михаил (email: E-MAIL_АВТОРА)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
function sch_load_script() {
wp_enqueue_script('my-script', plugins_url('my-script.js', __FILE__));
}
function sch_change_post($content) {
$content .= "Еще кусочек текста";
return $content;
}
add_filter('the_content', 'sch_change_post');
add_action('wp_enqueue_script', 'sch_load_script');
?>
И вот файлик кторой лежит в той же папке my-script.js (он не работате). А вот его код:
Код:
alert("Не работает!!!");
Простите за такойе колличество кода, но блин, что мне вписать надо что бы это окошечко появилось?????Пожалуйста помогите!!
 

lekzd

parse error: parse error, unexpected T_STRING...
Регистрация
17.02.2011
Сообщения
1 125
Код:
function sch_change_post($content) {
$content .= "<script type='text-javascript' src='my-script.js'></script>";
$content .= "Еще кусочек текста";
return $content;
 

CamaroSS

Well-Known Member
Регистрация
21.02.2012
Сообщения
176
http://codex.wordpre...on_plugin_pages

Код:
function my_plugin_admin_init() {
	 /* Register our script. */
	 wp_register_script( 'my-plugin-script', plugins_url('/script.js', __FILE__) );
}
function my_plugin_admin_menu() {
	 /* Register our plugin page */
	 $page = add_submenu_page( 'edit.php', // The parent page of this menu
								 __( 'My Plugin', 'myPlugin' ), // The Menu Title
								 __( 'My Plugin', 'myPlugin' ), // The Page title
	 'manage_options', // The capability required for access to this item
	 'my_plugin-options', // the slug to use for the page in the URL
								 'my_plugin_manage_menu' // The function to call to render the page
							 );
	 /* Using registered $page handle to hook script load */
	 add_action('admin_print_scripts-' . $page, 'my_plugin_admin_scripts');
}
function my_plugin_admin_scripts() {
	 /*
		 * It will be called only on your plugin admin page, enqueue our script here
		 */
	 wp_enqueue_script( 'my-plugin-script' );
}
function my_plugin_manage_menu() {
	 /* Output our admin page */
}
Возможно, имеет смысл ещё версию файла добавить

lekzd, это топорный какой-то способ.
 

BITH0VEN

Новичок
Регистрация
14.02.2013
Сообщения
2
Спасибо ребята я уже разобрался. Загвоздка была в том что я зацепку писал - "wp_enqueue_script"....букву s недописывал))...баран
 
Верх Низ