For plugins it is:
$plugin_url = plugin_dir_url( __FILE__ );
This works even if wp-content
is on a separate domain. You may get problems if your class is in a subdirectory of the plugin – you should probably make the __FILE__
a parameter for a function:
public function get_plugin_url( $base = __FILE__ )
{
return plugin_dir_url( $base );
}
You could also check if the parent directory of your class is the plugin directory and adjust the path accordingly.
Similar, for themes use get_stylesheet_directory_uri()
. It works for parent and child themes.
Related Posts:
- Serving precompressed content with Brotli on Apache
- How can I get a list of all enqueued scripts and styles?
- Load plugin scripts and styles only on plugin page
- How to prevent wordpress from loading old versions of jquery in wp_head();?
- Is it possible to change the attributes of a registered style or script before it fires?
- bloginfo(‘stylesheet_directory’) vs. get_stylesheet_directory_uri() and include(‘file.php’) vs. get_template_part()
- How can I avoid code duplication for a blog with lots of source code?
- How do I load custom scripts and styles for a page?
- How to rename wp-includes folder?
- What’s the correct way to include files in WordPress TwentyTen theme with it’s own jquery scripts and css?
- Styles and Scripts, Selectively enqueue across entire site
- ABSPATH not working! Any idea why?
- Get current user data from external PHP page
- Unable to load stylesheets and scripts to plugin settings page
- External system integration with wordpress
- Why does get_template_part() break variables?
- How to pass variables with get_template_part?
- Problems Including File
- How to include core files into plugin
- How to check if txt file exists inside template folder?
- Put CSS inside a PHP file and include it the right way
- What’s the best way to ‘include’ a file in WordPress?
- locate_template function – File not getting included
- Add stylesheets and js to template files when shortcode is used
- Correct check for any admin page with editor
- List All Enqueued Scripts and Styles
- Styles and scripts inside template part
- Enqueuing a script before anything else
- Can not include file from plugin into theme
- wp_enqueue_script was called incorrectly Issue when active plugins of WordPress Admin Bar Improved
- Include tags from array, ignore the rest in get_the_tags
- Minimizing scripts & css files that plugins add
- PHP files included within functions.php don’t work from admin area
- Wp Enviroment problem with included file
- Completely isolate a plugin view so it doesn’t load the theme
- Order of WP page load (including widgets, php, plugins, media, templates, and CSS) [duplicate]
- Having trouble linking to file using relative path
- How can I include an external file in a post or page?
- is there a way to get all queued scripts/styles into a template without `get_header()`?
- Including php file in directory above WordPress installation
- add_feed failed to open stream
- Load content From Include File within plugin
- including Zend Gdata library path error
- WordPress Sudden Loss of All CSS And Tons of JQuery Errors
- What about “inc” (include) files and Child Theming? Is it possible?
- Make changes in /includes/http.php update safe
- Need to override file included in parent theme
- Class works in Admin, not found on Front End
- if statement parent page for child pages
- Disable load scripts and styles not working
- add_action outside a plugin
- Add page as static html into another page
- Adding css and js to a blank page created with custom template
- How to include Elementor CSS in custom php file [closed]
- Open source social media icons to download and use on website? [closed]
- How to make a monopoly board using css grid?
- What’s the difference between SCSS and Sass?
- CSS reset – What exactly does it do?
- When to use margin vs padding in CSS [closed]
- SVG center horizontal and vertical line
- Can I change Bootstrap button color?
- How am I supposed to use index.html?
- Is it bad practice to comment out single lines of CSS with //?
- Half circle with CSS (border, outline only)
- How to draw a half circle (border, outline only) [closed]
- CSS calc width and height values
- Column order manipulation using col-lg-push and col-lg-pull in Twitter Bootstrap 3
- What is the difference among col-lg-*, col-md-* and col-sm-* in Bootstrap?
- Adding border to SVG image
- What does !important mean in CSS?
- Failed to load resource: the server responded with a status of 404 (Not Found)
- Random gradient background color
- CSS Circle with border
- How to horizontally center an element
- Center image using text-align center?
- Unblur content inside blurring background div
- How do I make a transparent border with CSS?
- Failed to load resource: the server responded with a status of 404 (Not Found)
- Failed to load resource: the server responded with a status of 404 (Not Found) css
- How to change CSS using jQuery?
- Set line spacing
- See answer keys in Google Form (quiz) source page?
- CSS Background Opacity [duplicate]
- Remove blue underline from link
- Angular: conditional class with *ngClass
- CSS Background Opacity [duplicate]
- Outline effect to text
- Customize Bootstrap checkboxes
- Making a
- Converts scss to css [closed]
- React.js inline style best practices [closed]
- Remove class using jQuery
- What is a user agent stylesheet?
- Using two CSS classes on one element
- What is the difference between CSS and SCSS?
- What is a user agent stylesheet?
- How do I vertically align text in a div?
- Is there a CSS parent selector?
- Hide scroll bar, but while still being able to scroll
- CSS background-image-opacity?