Include Paths Reference
Simple, entry-level stuff right? But how often do you have to fuss around a while before you succeed at including that darn file?
PHP:
define('ROOTPATH', __DIR__);
Result: /Applications/MAMP/htdocs/ankrommoisan/wp-content/themes/ankrommoisan-2017/template-parts/page
$_SERVER['DOCUMENT_ROOT'];
Result: /Applications/MAMP/htdocs
$_SERVER["HTTP_HOST"];
Result: localhost
getcwd();
Result: Current Working Directory, ie: /Applications/MAMP/htdocs/active-theme-folder
WordPress:
get_template_directory();
Result: /Applications/MAMP/htdocs/site/wp-content/themes/active-theme-folder
Javascript:
window.location.pathname
Example: “check-path-example”
window.location.href
Example: “https://js-tricks.info/check-path-example”
window.location.origin
Example: “https://js-tricks.info/check-path-example”
jQuery:
$(location).attr('host')
Result: path
$(location).attr('href')
Result: href
$(location).attr('protocol')
Result: protocol
HTML File Paths
src="image.jpg"
Result: file is in the same folder as the page using it
src="images/image.jpg"
Result: file is in an images folder that resides in the current file’s location
src="/images/image.jpg"
Result: at the web root there is an images folder with the file inside it
src="../image.jpg"
Result: the file is in a folder one level up from the current file’s location
../ is not to be confused with ./ which points to the current directory in a computer file structure setting