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]
- Remove class using jQuery
- CSS Font Border?
- How to change btn color in Bootstrap
- FontAwesome icons are not showing, Why?
- text-overflow: ellipsis not working
- How do you #include files in java?
- How do I right align div elements?
- How can I center
- into a div?
- How to overlay one div over another div
- How can I apply styles to multiple classes at once?
- CSS !important not working
- WordPress how to remove blocksy theme price and put my own price
- How do i use fontawesome icons in TinyMce editor?
- How do I add JavaScript that will execute on all my sites in Multisite?
- Change logo on each page of University Hub theme [closed]
- How to center a video [closed]
- How To Keep Posts from Being Displayed Two or More Times on My Homepage? [closed]
- Why isn’t “background-image: url”working with Bootstrap carousel on WP?
- Using uncss or similar with WordPress?
- How can i add note, caution, warning quote inside the text? [closed]
- Add to Cart button woocommerce background and with doesn’t display correctly
- Scripts at the end of the page
- Impossible to call wordpress function inside an include?
- Switch from hover to click on Twenty Twelve Menu
- height should be set to auto to avoid pixelation in the post thumbnail function
- Implementing a simple slider in code?
- Scripts not loading when using the wp_enqueue_scripts action
- Basics of changing plugin output
- custom header navigation has odd spacing [closed]
- Add a specific css to a widget
- Error in node.js webpack-cli failed to load config, typeError: ManifestPlugin is not a constructor
- Why would a theme writer put their CSS in one long string? [closed]
- customize continue reading
- how would I change background color of a theme using a plugin?
- Target admin page body via CSS class
- How to put search bar & logo in the “primary navigation” storefront theme?
- Overriding inline !important CSS with Javscript code snippet with media query
- Error on clicking ‘Screen Options’ tab only at Products-related editor screen(s) and for specific user
- Why is css not applied on paginated query?
- How to add style in functions.php depending on conditions?
- Delete all blogs on multisite
- how to make social media buttons start only from under a photo/post?
- responsive screen not working [closed]
- which php or css file has generated an inline style in WordPress that overwrites my css
- Post interior margin in twenty eleven theme
- Import css file from node_modules using @wordpress/scripts