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
- I have issue to retrive post thumbnail with rest api
- Custom page template from plugin does not work with pre-installed themes in WordPress 6.6.1
- How to Include a Loop Template File in a Plugin
- Write to / remove from default .htaccess file from plugin?
- Deactivate Plugin on Theme Switch
- Update Option Error: Notice: Undefined index
- How can I display a contact form for out of stock products in WooCommerce?
- ‘Customize’ button in admin bar for CSS
- Pass a php string to a javascript variable
- get shortcode value
- How to get number of Affected rows from wordpress dbDelta() function
- Unable to install theme recommended plugins on Multisite
- Theme or Plugin: Where should I write my code?
- Show price with Geo IP location
- WordPress Ajax Callback
- Add category to body class
- The called constructor method for WP_Widget in GFWidget is deprecated since version 4.3.0! Use
- Plugin Development sqlite or WordPress’ database
- More than one text-domain is being used because of the included templates for plugins
- How to review WordPress website php version compatibility?
- Plugin Deactivate Self on Activation Errors
- printf – problem to understand code
- Custom Post Type Plugin not loading category template and loading 404 instead
- How to Know if a Plugin can be used with my Theme [closed]
- Sending email from inside a plugin using PHP PEAR
- Auto delete WordPress users according to time
- How to cancel WordPress’ action/filter when using OOP with anonymous callback
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- How to trigger $_GET request within admin plugin page?
- Wp favorite posts get user favorites in profile using buddypress [closed]
- Storing Options in a Shortcode
- Why isn’t admin_notices displaying my text? [Simple Plugin, Beginner]
- How to generate video out of images via WordPress plugin
- Is it possible to use WordPress as an online portfolio for text content? What kind of theme would I look for?
- How can I get WordPress to save comments in markdown format?
- add_query_arg not working
- problems with wordpress and php version 5.3.3-1
- WooCommerce get_price returning wrong price when used via ajax
- How to ‘clone’ a wp plugin to make small changes
- Not able to open category post [closed]
- Open Post Thumbnail in New Child Theme File in WordPress
- add mediaelement.js plugins into WordPress video player control bar
- Shortcode button dosent work for all posts. Work for first post only
- Where should I save an API key of my user when installing my plugin?
- Prevent a plugin from being automatically activated
- Reusable functions and tools (Framework)
- Is Wrapping intval() Around esc_attr() Redundant for Escaping Input?
- Programatically download a plugin
- Accessing post’s meta data based on user’s click of a post
- How To Clean The Malware Infected & Hacked WordPress Websites? [duplicate]
- Do I still need a theme to use page builders?
- Error shown for Trying to get property ‘roles’ of non-object in WordPress After Content for User Roles
- How to prevent users to download videos from lms website?
- Preferred way of cacheing a value in php
- Redirecting to home page after login as custom role WordPress
- WordPress Redirect Not Working – AJAX Callback Response Not Picked Up
- How to Use Parameters with a Do_Action Function Within PHP Tags
- Add keywords meta to index.php page
- Custom form action to handle data inside a plugin
- How to remove html code in excel downloads using phpspreadsheet with wordpress plugins shortcode
- Add Product Subtitle to Woocommerce Product Page
- Self deactivate plugins after an action occurs
- How to get current post user id
- wp_redirect() not working in Insert PHP plugin in WordPress
- Download any file after submitting a form [closed]
- Only Homepage not loading properly
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- woocommerce 3.2.1 not sending order notification emails
- WordPress takes too much time (100 seconds) to load – Front end and back end