Skip to main content

Master Function - tempdir() and get_tempdir()

Author

Robert Loncaric

Timestamps

Created: 01 August 2024
Modified: 01 August 2024

Probably my favorite function. Used to get the template directory.

tempdir() gets the directory and renders it
get_tempdir() gets the directory and returns it, no render

These are already in Master.

Steps

Goes into functions.php if not already there.

Simply call it like this: <?php  tempdir(); ?>

Goes into functions.php if not already there.

Simply call it like this: <?php echo get_tempdir(); ?>

if ( ! function_exists( 'tempdir' ) ) {
    /**
     * Get the template directory URI.
     *
     * @return string Template directory URI.
     */
    function tempdir() {
        echo esc_url( get_template_directory_uri() ) . '/';
    }
}
if ( ! function_exists( 'get_tempdir' ) ) {
    /**
     * Get the template directory URI but don't echo it automatically.
     *
     * @return string Template directory URI.
     */
    function get_tempdir() {
        return esc_url( get_template_directory_uri() ) . '/';
    }
}