Is there a way to determine if my current PHP file is within the plugins’ folder or within the themes’ folder
Broadly you always have path to current file (__FILE__
) so you can always examine it for where you are and compare with context. This might be good enough in custom site, but likely too brittle for public code. There are plenty of edge cases with paths since they can be highly customized.
What you have is not just asset problem, but dependency problem — how do you reuse multiple components, in different ways, and without conflicts.
Personally I’d strongly consider looking into Composer, since it’s de–facto way to manage dependencies in modern PHP. It’s… not perfect for quirks of publicly distributed WP extensions, but your case sounds more like custom–work focused anyway.
Related Posts:
- Which method is best to enqueue scripts
- URL parsing – what is it?
- What is the correct way to convert the absolute path of the executing script to a URL, in WordPress?
- How do I test my localhost WordPress project with VirtualBoxVM?
- Is it possible to configure WordPress’s Core Files to accept duplicate Child Categories?
- hijacking home_url for root relative paths
- wp_enqueue_script not loading my custom js file
- get_template_directory() returns wrong address on VPS
- Relative URLs within site
- Make custom system url
- bloginfo no show the right path
- Accidentally Changed WordPress Url
- Automatic short URL in posts
- How to get the path to the current theme?
- How do you retrieve a post by slug name through REST API?
- Why “?v=hash” is added to my URLs? [closed]
- Detecting a WordPress URL without doing a full HTTP GET?
- How does WordPress generate URL slugs?
- How does routing on wordpress work?
- Redirecting to old domain after migration
- Custom plugin route in WordPress
- Why is ?doing_wp_cron being appended to my URLs
- Unwanted media library URLs in posts?
- Symbolic Links on dev box with plugins and stylesheets
- How to call images from your plugins image folder?
- How to remove file versions from the file source links in wp_head?
- use query string in URL to display content on the page
- Change default URL path (/blog/) of blog posts
- Difference between esc_url() and esc_url_raw()
- Use a separate upload folder for custom post attachment upload
- How to deal with WordPress on localhost
- Posts URL structure like site.com/category/the-post-title
- Problem with guids and absolute links
- How to convert the file path to a URL of the same file?
- Add menu and submenu in admin with a URL instead of slug?
- Update media file url in wordpress media library
- Why is WordPress saving full-urls to the database?
- Get taxonomy slug from url
- Load images with http urls inside https post
- Remove All Query Arg
- Add forward slash on categories url (serve one version of a url)
- Pulling a parameter out of the URL of a WP link without “?” or being sent to a different page
- How to remove /index.php/ from URL’s
- Run WordPress frontend and backend in different domains
- How to get WordPress to save upload file beyond web root [closed]
- How to set global variable in functions.php
- Force the Website URL to Include “www” and to be Upper Case?
- How to remove “http://” When Echoing URL?
- Change logo url link
- WordPress and $_GET Params
- Can’t login after my site was moved to a new server
- WPML Get url without outputting
- How to inject custom url path for page ?
- List of default WordPress URLs
- Why WP encodes UNICODE (UTF8) containing urls? Any drawbacks of UNICODE url?
- Adding a hook to ‘parse_request’ so that siteurl/pagename/xyz ignores “xyz”
- How to have numeric URLs in Posts and Pages
- Unable to load static front page on home url
- Force home page to be https?
- Why WordPress automatically removes http from the url of my website’s sub domain?
- add_query_arg() One Key with multiple values
- Weird: /?name in URL leads to blog
- I am Looking to append URL Parameter to all URLs
- How do I amend the fixed “author” part in the URL?
- WordPress Move to SSL How to Update Media Assets to HTTPS?
- Dynamic URL generates dynamic content
- Moving wp-content outside of web root?
- Pages redirected to attachment post
- Generate one time URL
- In Settings>>General I am missing some fields
- Change homepage url
- As soon as I add a custom query_var using the filter, my pages point to an archive page – why?
- Is dynamic URL possible in WordPress
- Adding target and _blank as it’s value to the allowedtags
- How to update media links in WordPress after migration?
- permalink for category pages and posts
- Why doesn’t WP_PLUGIN_DIR definition use DIRECTORY_SEPARATOR?
- Accessing the Current URL in a Text Widget for a Facebook Share Button?
- issues including a file from a plugin directory
- Is ‘name’ a reserved word in URL’s?
- get_site_url is not returning anything?
- Check what is at URI (post, archive, etc…)
- What’s the proper way to use wp_enqueue_script/style?
- Get url from file uploaded in Media Library
- How to create a custom page base on URL for WordPress?
- How to make menu items active based on hash
- Use image url with add_image_size
- Multiple domain names for one site
- How to always rewrite author archive page URL even if the author does not have a post
- Remove ‘wp-content/themes/themename/’ from Image path
- Alias ‘wp-content’ directory to something shorter (framework?)
- How can I change all links on pages to point to a different domain from where the site is hosted?
- Best way of removing emoji support from url / slug only
- Allow UTF-8 characters in the user slug part of URL
- WordPress converting ../url to http://../url
- Password protected page Hash url
- Which of WordPress’s .php files need to be directly accessible via HTTP?
- Remove site root trailing slash
- home_url(); showing current page instead of site address
- Why ids in urls don’t work but slugs do?