ap_get_theme_url( string $file, mixed $plugin = false, boolean $ver = true )

Description #

Get url to a file Used for enqueue CSS or JS.

Parameters #

  • $file
    string (Required) File name.
  • $plugin
    mixed (Optional) Plugin path, if calling from AnsPress extension. Default value: false
  • $ver
    boolean (Optional) When true, AnsPress version will be appended to file url. Default value: true

Changelog #

VersionDescription
2.0Introduced.

Source #

File: includes/functions.php

function ap_get_theme_url( $file, $plugin = false, $ver = true ) {
	$child_path  = get_stylesheet_directory() . '/anspress/' . $file;
	$parent_path = get_template_directory() . '/anspress/' . $file;

	// Checks if the file exists in the theme first.
	// Otherwise serve the file from the plugin.
	if ( file_exists( $child_path ) ) {
		$template_url = get_stylesheet_directory_uri() . '/anspress/' . $file;
	} elseif ( file_exists( $parent_path ) ) {
		$template_url = get_template_directory_uri() . '/anspress/' . $file;
	} elseif ( false !== $plugin ) {
		$template_url = $plugin . 'templates/' . $file;
	} else {
		$template_url = ANSPRESS_THEME_URL . '/' . $file;
	}

	/**
	 * Allows filtering url of a AnsPress file.
	 *
	 * @param string $url Url of a file.
	 * @since 2.0
	 */
	return apply_filters( 'ap_theme_url', $template_url . ( true === $ver ? '?v=' . AP_VERSION : '' ) );
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment