Plugin within a theme – sounds like something new. You might not find function in this context. Let’s create ours:
<?php
/**
* Get My Plugin URL.
* @return string.
*/
function wpse295740_get_plugin_url() {
// http://example.com/wp-content/themes/my-theme/inc/my-plugin
return get_template_directory_uri() .'/inc/my-plugin';
}
/**
* Get My Plugin Path.
* @return string.
*/
function wpse295740_get_plugin_path() {
// eg. /home/user/var/www/wordpress/wp-content/themes/my-theme/inc/my-plugin
return get_template_directory() .'/inc/my-plugin';
}
You can make it more complex using the __FILE__ magic constant etc. – see the original plugin_url() source. And plugin_dir_path() too. And trailingslashit() and untrailingslashit() are there too for ease.
Related Posts:
- How to get the active theme’s slug?
- Which hook callback has priority if both plugin and theme use the same hook?
- Uncaught Error: Call to undefined function get_user_by() after moving function from theme to plugin
- add_meta_box (Will display only in specific page admin WordPress)
- All sites themes functions.php have been changed
- Why namespaces are rarely used in WordPress plugins?
- My single.php page does not show the related data to the post which is clicked
- how can I do something on new user registration?
- Use $variable from file1.php in file2.php (different file paths)
- How to make a dynamic css class whose name changes every visit to confuse scraper
- I receive taxonomy id
- speed up pagination for huge database
- Inserting Plugins Into Blank Space of Externally Designed WordPress Theme
- Plugin Admin panel checkbox unchecked after submit
- uncaught TypeError: Cannot read properties of null (reading ‘classList’) custom plugin
- Custom Plugin scripts from admin working in frontend
- WordPress Cache delete on plugin uninstall
- Replace old theme that understand old css (vcex_icon_box css_animation)
- Remove a div class with condition
- Hooking into the HTML header container
- How to get a post views count using ‘WordPress popular posts’ plugin
- How can I make the search bar in my wordpress site search all of the pages rather than just the blog posts?
- I want add repository theme folder
- Things that saved lose when logout
- Woocommerce: deleted single-product.php, everything still works. How is it possible?
- What is the process for reimplementing a back up WordPress?
- Template from scratch: Sidebars not showing widget
- Display static pages instead of category, in code
- wordpress illegal string offset ‘parameter’ error
- Two sites one PC
- Real estate schema markup not showing up on Rich Results test
- Custom page template from plugin does not work with pre-installed themes in WordPress 6.6.1
- How can I see all the actions attached to an “add_action” hook?
- Shared functionality in plugins and themes
- How can I import a class privately into a plugin?
- Problems with autoloading classes via sp_autoload_register / maybe interfering WP-specific autoloader
- Can we completely remove the WordPress Sitemaps (WordPress 5.5)?
- Updating WooCommerce variable product stock issue
- Rename existing old uploaded images containing accented French characters (not during upload)
- White text on white background in TinyMCE when wp_editor is called in WP 3.9
- Loading class files via autoload method
- Adding a custom line of text to php code
- Modifying Footnote Plugin for Descriptive Title Attributes
- I would like to use create a function in my custom plugin to tell WP to use a different header
- Escape when echoed
- Make id column as AUTO INCREMENT on plugin activation
- Redirecting to home page after login as custom role WordPress
- Notepad sticky plugin
- WooCommerce Custom Product to checkout
- How to stop or remove an action being called inside a function of an extended class
- How to simultaneously access the same MySQL database in the main column and sidebar of WordPress?
- Date calculations from 2 custom fields
- Easiest way to add dropdown to a page
- Assign / update custom field value for all posts (How can I assign only to posts without custom field value?)
- How to enable specific plugin only based around shop manager role?
- Adding a new field to the address field type in gravity forms
- Show admin notice on incorrect value on form field
- WordPress adding a menu page when activating a plugin
- Create a plugin from within WordPress
- Call plugin with php function
- What happens when WordPress memory limit is exceeded?
- Making that Admin Bar transparent or a blue color
- how to activate a plugin inside a theme
- How do I add $_SESSION[”] to my wordpress page?
- There has been a critical error on your website – won’t fix no matter what
- Override/ignore CSS from active theme as not to interfere with my custom CSS
- How can i add simple code in only in posts by function.php
- Hide DIV if empty – Plugin Gallery
- How to use custom Javascript code inside a plugin?
- How to use printf to output two links?
- why need theme,if page builder is there in wordpress [closed]
- 2 wordpress site same database
- How to redirect to a page after the form is submitted
- Identify current wordpress theme
- WP Insert Post If user refreshes override new post
- How to makes changes on the shop/category/tag pages but not on the product pages in woocommerce?
- Javascript console errors and WSOD on edit post pages
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- How Can I Create A Form In WordPress For Subscribers To Alert Them about new Listing posted?
- Getting Fatal error: Uncaught Error: Call to undefined function plugin_dir_path() when linking to another file within my wordpress plugin
- the content of the uploads folder gets deleted periodically, how to figure out what causes it?
- front end editor creation for Restropress plug in – displaying information from a WP admin area, on a different URL
- Custom Field used to allow a Free Story; no longer works
- How to send new visitor to a splash page for only one time in wordpress?
- Cron job shedules replace?
- Create a form and have custom menu display based on user answers?
- Can i add custom code in Source in specific page, Header from function.php?
- Problem with conditional woocommerce custom checkout field
- GET web api method from a WordPress PHP script
- How to add the functionality of WordPress needed to be installed to be mandatory while installing themes
- Editing Global Variables from Inside Functions
- Posting code inside the post instead of in the template file using shortcode
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- conditional tags for the output of a plugin
- How to tweak a plugin without preventing it from updating
- Place max_execution_time in plugin [closed]
- Function not being called on form submit, only blank admin-post.php page
- WordPress Convert queries to slashes using function.php
- Getting table to format properly in RSS feed emails
- PHP Deprecated function Optional parameter $function