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
- Remove Open Sans from Twenty Twelve theme
- Enqueue Google Web Fonts Without Messing Up Symbols In URL
- Inbuilt style for jquery-ui-datepicker
- Why is style.css not being enqueued?
- How to enqueue style before style.css
- How to add stylesheets only to pages with specific shortcode?
- What is the correct way to enqueue multiple CSS files?
- Remove wp_add_inline_style
- Is it possible to enqueue a raw CSS string directly from within a template file?
- Why I can’t add a CSS style in this WordPress theme?
- Why isn’t my theme processing SASS?
- Adding style sheet to specific page
- How do I load custom scripts and styles for a page?
- WordPress Displaying Thumbnails Vertically
- When enqueing a stylesheet, is it possible to remove the type attribute? [duplicate]
- Enqueued Stylesheets Effecting Admin Styles
- wp_enqueue_script + how to load JS or CSS in one URL merge call?
- Prevent CSS/JS loading when plugin is not used
- Changing Font-Size based on specific Font thru javascript
- The correct way to include JavaScript and CSS in my WordPress Themes
- Collapsible button inside a ul list does work in jsfiddle but not in WP
- Is it possible to change the path of a css file that is registered through wp_enqueue_style()?
- get_stylesheet_uri returns wrong path
- Override load-styles.php with admin screen css
- Can “ and “ tags be used in the HTML editor?
- JavaScript added as link/stylesheet
- Deregistering a script in WordPress seems impossible
- Write text below a specific part of a sentence
- How the Css File is Linked without calling it in header.php?
- Show enqueued CSS and Script in custom header
- Adding external stylesheet after ALL other styles
- Eliminate render-blocking JavaScript and CSS in above-the-fold content
- Different ways to load child theme css
- Enqueueing a script and a style sheet not working
- How to override Bootstrap css with my child theme css in wordpress?
- How to create fa-bars animated menu
- Does costum code in the root folder get lost when wordpress is updated?
- How to organize priority of plugins CSS files?
- CSS Minification
- why this media query is not working / not loading when I put it in child theme?
- Why is this jquery / java script code not working in mobile / in devices?
- Seperate functions.php for part of site
- Enqueuing a script before anything else
- Child Theme CSS not showing at all
- Faster fonts on mobile
- wp_enqueue_scripts and CSS
- Ordering stylesheet above using functions.php
- Display Something in the Header After All Styles are Loaded
- How to change “““ to “““?
- Conditionally enqueue a stylesheet based off of a javascript click event
- 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?
- Including Styles and JS files to work ON my plugin interface
- prevent HTML output if custom field is empty [closed]
- 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
- Button doesn’t work in the profile panel
- Hide Tab Titles from Tabs Block
- How can I hide this custom slider while Elementor editing window is open?
- Dequeing Parent Fontawesome Deques Parent Styles
- 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]
- Web Developer Console: “Slow network is detected.” with fonts
- 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
- Controling css order
- Why are my parent styles loading after my child styles?
- How to make CSS load live based on options clicked in the theme customizer?
- Change Login CSS – Include instead of echo
- How to implement a JavaScript and CSS file for my WordPress homepage?
- Browser stacks different versions of style.css
- How to remove audio player styles added by mediaelement.js JavaScript?
- Can I upload my HTML/CSS/Javascript game onto a WordPress page?
- Enqueue MCE Editor CSS in admin page