Don’t hardcode a directory in your code, use the following path finding

Local Paths

<?php plugin_dir_path($file); ?>

$file is the file name

< ?php
echo plugin_dir_path( __FILE__ );
? >

__FILE__ is the constant stand for the current file

Result:

/home/jeeradat/domains/jeeradate.com/public_html/dev/wp-content/plugins/insert-php/

Code:

< ?php

echo plugin_dir_path( __FILE__ ) .’js/scripts.js’;
? >

Result:

/home/jeeradat/domains/jeeradate.com/public_html/dev/wp-content/plugins/insert-php/js’

URL Paths

code:

echo plugins_url().”<br/>”;
echo includes_url().”<br/>”;
echo content_url().”<br/>”;
echo admin_url().”<br/>”;
echo site_url().”<br/>”;
echo home_url().”<br/>”;

Result:

http://jeeradate.com/dev/wp-content/plugins
http://jeeradate.com/dev/wp-includes/
http://jeeradate.com/dev/wp-content
http://jeeradate.com/dev/wp-admin/
http://jeeradate.com/dev
http://jeeradate.com/dev

Leave a Reply