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 add stylesheets only to pages with specific shortcode?
- 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
- WordPress Displaying Thumbnails Vertically
- When enqueing a stylesheet, is it possible to remove the type attribute? [duplicate]
- 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()?
- Handling URLs in WordPress application
- get_stylesheet_uri returns wrong path
- Override load-styles.php with admin screen css
- CSS file not registering through add_action
- getting url in wp_enqueue_style
- Can “ and “ tags be used in the HTML editor?
- JavaScript added as link/stylesheet
- Write text below a specific part of a sentence
- Adding external stylesheet after ALL other styles
- Eliminate render-blocking JavaScript and CSS in above-the-fold content
- Enqueueing a script and a style sheet not working
- 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?
- How do I make header.php use different css for different pages?
- Load CSS in footer, like your can with JS?
- Is the wp_enqueue method efficient?
- How can I get the search form to be selected automatically?
- Implementing a simple slider in code?
- Cannot set property ‘className’ of null at setThemeFromCookie
- My CSS suddenly doesn’t load anymore [closed]
- 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?
- CSS getting injected into index from somewhere after theme/custom CSS is loaded, overriding all of my CSS [closed]
- 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
- is there a way to get all queued scripts/styles into a template without `get_header()`?
- Plugins not showing up for custom template
- Dynamically add Js
- 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)
- Advanced method to control cache of enqueued style/script
- Save custom option in CSS file
- broken internal JavaScript and CSS files
- How to enqueue stylesheets in child-theme functions.php?
- 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?
- Set different css stylesheet for specific pages [duplicate]
- My Child Theme CSS Isn’t Working
- Font size decreases when child theme is created from parent theme?
- How do I dequeue a Stylesheet, stored in an ‘Assets’ folder?
- Import HTML code that loads css and javascript into specific page
- custom post with loading script per single post
- Replacing parent theme’s IE-specific CSS
- What can cause JavaScript and CSS files to be minified?
- Move main menu to top of screen
- Interactive maps in wordpress
- 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?
- hide specific css and js files in specific page wordpress with id or without?
- CSS Selector to override default theme.json custom properties in theme stylesheet