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
- How do you retrieve a post by slug name through REST API?
- 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
- Unwanted media library URLs in posts?
- How to remove file versions from the file source links in wp_head?
- Add menu and submenu in admin with a URL instead of slug?
- Update media file url in wordpress media library
- Change logo url link
- Dynamic URL generates dynamic content
- Pages redirected to attachment post
- As soon as I add a custom query_var using the filter, my pages point to an archive page – why?
- Why doesn’t WP_PLUGIN_DIR definition use DIRECTORY_SEPARATOR?
- What’s the proper way to use wp_enqueue_script/style?
- Remove ‘wp-content/themes/themename/’ from Image path
- Remove site root trailing slash
- How do I override the emoji url?
- Site broken after using URL Change in Admin
- Can URL remain the same if migrating from Drupal?
- How to add domain security certification, in WordPress website?
- Custom Post type permalink structure with custom_post_id
- Setting a url for a page
- pass user id in slug and get user information
- How to allow — in category name
- Request parameters in $_GET do not match URL called
- WordPress custom search url
- 404 error when passing “cat” parameter to URL
- How can I change a media attachment URL/slug, so that I can use that slug for a page?
- Twitter shortlink 404 not found [closed]
- Remove Trailing Slash from Category Base and Tag Base
- how to trace a file by the route url
- Get root folder without domain
- Block direct url enter
- How do you make homepage redirect to it’s slashed version?
- Can i have access to my WordPress Website again?
- Site transferred to new server produces 404s
- How can I make my blog urls have words of the title in them?
- Website Address Keep redirect to website after migration attempt
- Change URLs depending on alias
- Passing values through url for checkbox fields with same name to get?
- How do I avoid messing up URLs when switching from example.com/subdir to example.com?
- Made WordPress URL and site address URL the same
- How can i get rid of wp in front of URL
- Alternatives to site_url() and get_template_directory_uri()
- Blog post – single.php url
- Unicode characters are saved in a funny way in the DB
- Replace category name with article id in wordpress urls
- Redirect Old wordpress url to new wordpress url
- Page not found when trying to link to files in child theme directory
- Localhost access after changing URL
- WordPress Primary Category Changes After Import, Permalink Issue
- Changing siteurl in the database not working
- How to set wordpress url on local host to access it via VPN
- unique url access control
- I found weird email address appended to some of my URLs, what does that mean?
- How to get custom URL routes property_id in wp php plugin?
- index.php shows up in url
- Why my WordPress website homepage automatically adding cs_preview=true query parameter to the url?
- how to remove this #.XsZOUWhKjIU from my wordpress url
- URL redirects of webpage
- What is this extension on mu web URL?? It leads to a blank page. what is causing it/?
- Cannot Save Changes After Updating URL Settings
- Avoiding the -2 in slugs
- How to encode correclty an url with the char “&” for an email?
- How do i create navigation links like this in wordpress? [closed]
- Blog post Links leading to home page [closed]
- URL Structure for translated articles
- Custome home page url
- Inject dynamic strings in urls
- Pass post title as URL parameter
- Let WordPress to go opening an external URL
- Change default query parameters
- How to pass parameters thru URL?
- problem getting audio url
- Domain name to a page
- wp-login.php ampersand in url results in 404
- How to tell if a script is being executed from a plugin, a theme or a child theme in WordPress?
- How to eliminate the Web Address / Web Link textbox from comment forms
- URL displays different page (a loop)?
- Change path/url of admin-bar.min.css
- Append custom parameter to taxonomy/term URI
- Why is my WordPress install using full server directory paths for media URLs?
- Typing local WordPress URL works, but clicking the same link does not
- Images in sub-pages fail to load
- How to prevent URL-modification when page title contains digits only?
- Block a specific url request
- What purpose does /embed/ URL have and how to avoid SEO problems?