Not with the WordPress API, but you can do it with vanilla PHP pretty easily.
<?php
//Get the full path of the local directory first.
$fullpath = __DIR__;
//check if you are in a theme directory or a plugin directory
if (strpos( $fullpath, 'themes' ) !== false )
{
//It's a theme, use get_stylesheet_uri
} elseif ( strpos( $fullpath, 'plugins' )
{
//It's a plugin, use plugins_url
} else {
//It's somewhere else entirely.
}
Related Posts:
- How to combine multiple CSS files and concatenate JavaScripts if WordPress recommends enqueuing them?
- How to insert html/css/javascript code to wordpress plugin
- enqueing Javascript and CSS
- Bootstrap 4 Optimization
- Could the WP script/style loader be used to concatenate and gzip scripts and styles in the front-end?
- wp_enqueue_scripts, wp_register_scripts, wp_print_scripts: i’m confused
- Use wp_enqueue_scripts, not wp_print_styles?
- Custom Admin CSS styles to style media uploader?
- How to integrate my HTML and javascript into my child theme
- Child theme stylesheet not always overriding “index”
- Custom Plugin – CSS works, JS doesn’t
- How can I force Dynamic CSS via ACF values to update on page load?
- functions.php – inject inline css from file
- Load custom CSS before admin CSS
- Theme JS is available but theme CSS isn’t
- Including CSS files in HEAD based on page content
- Dequeue styles with query doesn’t work
- Bootstrap Integtration
- Enqueue CSS and Script only if needeed
- plugin not loading my css and js
- difference between code for admin, user facing (css, js)
- How can I get a list of all enqueued scripts and styles?
- My CSS suddenly doesn’t load anymore [closed]
- Conditionally enqueue a stylesheet based off of a javascript click event
- get_template_directory_uri() generates wrong path
- Append style tag in head while shortcode runs
- How can I move my custom css to the very bottom of the head section?
- Remove CSS & JS from
- CSS getting injected into index from somewhere after theme/custom CSS is loaded, overriding all of my CSS [closed]
- How to Add a Read-only Textbox With Text in it That Has a Button to Copy it?
- How would one set or override a Fallback font for characters in second language?
- First element/selector of enqueued CSS file breaks
- I want to set global directory locations for my CSS and JS locations. How?
- ACF Pro with SlickJS [closed]
- Show/Hide Div for Login Mask
- Including Styles and JS files to work ON my plugin interface
- prevent HTML output if custom field is empty [closed]
- is there a way to get all queued scripts/styles into a template without `get_header()`?
- Plugins not showing up for custom template
- Equal height sections in custom Headway Theme
- W3TotalCache and Javascript — what should go where, when?
- How would I create the same popup in css and javascript as the one in contact button on the site https://www.sublimotionibiza.com/es/main.html [closed]
- Combine CSS Files without plugin
- Dynamically add Js
- Button doesn’t work in the profile panel
- WordPress Rest Api access the header and extract stylesheets URL
- Invert porfolio item order
- How to make a function to play only on the home page?
- Embed widget from external source (Zendesk)
- Hide Tab Titles from Tabs Block
- Advanced method to control cache of enqueued style/script
- How can I hide this custom slider while Elementor editing window is open?
- Save custom option in CSS file
- broken internal JavaScript and CSS files
- How to enqueue stylesheets in child-theme functions.php?
- Dequeing Parent Fontawesome Deques Parent Styles
- Getting and setting CSS variables with JQuery in WordPress backend fails
- Add inline CSS to login page with wp_add_inline_style
- Unable to use Datepicker in a table when inserting a row
- Why can I not deregister my style and script on custom post type?
- How to properly hide the div of an inline collapsible button?
- Change the version of default style.css in wordpress
- Set different css stylesheet for specific pages [duplicate]
- My Child Theme CSS Isn’t Working
- Web Developer Console: “Slow network is detected.” with fonts
- Font size decreases when child theme is created from parent theme?
- How do I dequeue a Stylesheet, stored in an ‘Assets’ folder?
- How to display javascript banner in website header?
- How would I add this code to a single WordPress page?
- The placeholder text doesnt disappear
- Trouble with adding preloader to my home page index.html and index.js
- Import HTML code that loads css and javascript into specific page
- Controling css order
- custom post with loading script per single post
- Why are my parent styles loading after my child styles?
- How to make CSS load live based on options clicked in the theme customizer?
- Replacing parent theme’s IE-specific CSS
- Change Login CSS – Include instead of echo
- How to implement a JavaScript and CSS file for my WordPress homepage?
- What can cause JavaScript and CSS files to be minified?
- Browser stacks different versions of style.css
- Move main menu to top of screen
- How to remove audio player styles added by mediaelement.js JavaScript?
- Interactive maps in wordpress
- Can I upload my HTML/CSS/Javascript game onto a WordPress page?
- Enqueue MCE Editor CSS in admin page
- How do I add JS and CSS to WP (Flatsome)
- “Plate” theme broken after update
- Custom theme – Bootstrap CSS not loading via wp_enqueue_style or otherwise
- How enqueue CSS out of theme folder?
- How to optimise Text to HTML ratio for SEO by separating the HTML into multiple files?
- hide specific css and js files in specific page wordpress with id or without?
- Separate typography controls for titles and meta in a custom block?
- Enqueue Stylesheet on the front end and in the block editor Conditionally
- unable to find the document body in user-edit admin using javascript or CSS
- Identify and style the paragraph beginning w/o a class: based on a combination of common characters (CSS, JS)
- How do I remove/hide embed excerpts from posts
- Block style variations not enqueued for blocks inside HTML code dynamically rendered via JS
- Load RTL CSS using block.json for block development
- Twenty Twenty Four child theme stylesheet is not being enqueued in admin panel when editing pages