I have a plugin, which creates a panel on following page:
mysite.com/wp-content/plugins/myplugin/includes/mypanel.php
I want to use this panel on following page
mysite.com/mypanel
Solution that I tried was to using mypanel.php
as page template as below:
add_filter( 'page_template', 'wpa3396_page_template' );
function wpa3396_page_template( $page_template )
{
if ( is_page( 'mypanel' ) ) {
$page_template = dirname( __FILE__ ) . '/includes/mypanel.php';
}
return $page_template;
}
This way the page displays but none of the javascript works. So I have tried to import plugin's javascript in functions php.
add_action('wp_enqueue_scripts','Load_Template_Scripts_wpa83855');
function Load_Template_Scripts_wpa83855(){
if ( strpos(get_page_template(), 'mypanel.php') !== false ) {
wp_enqueue_script('wtd', $_SERVER['DOCUMENT_ROOT'].'/wp-content/plugins/myplugin/js/wtd.js');
}
}
Which resulted 403 forbidden error. I added tried adding an .htaccess folder into plugin's page but it continued to give error.
Please tell me what is the correct way to solve this problem.
EDIT: After some answers below (thanks everyone). I moved my codes to my plugin's page, and no more 403 forbidden error. But my buttons are not working, and I feel like my js file not run over the page.
My js file starts with: jQuery(document).ready(function()
Here final code on plugin's page:
/* Make tisort-tasarla page as template */
add_filter( 'page_template', 'wpa3396_page_template' );
function wpa3396_page_template( $page_template )
{
if ( is_page( 'tisort-tasarla' ) ) {
$page_template = dirname( __FILE__ ) . '/includes/tshirt-designer-design-template.php';
}
return $page_template;
}
/* Add Javascript to T-Shirt Design Page */
add_action('wp_enqueue_scripts','Load_Template_Scripts_wpa83855');
function Load_Template_Scripts_wpa83855(){
if ( is_page( 'tisort-tasarla' ) ) {
wp_enqueue_script( 'wtd', plugins_url( '/js/wtd.js' , __FILE__ ), array( 'jquery' ));
}
}
.htaccess
file? Also try usingplugins url()
to get the path to your plugins directory and see if it helps.