A possible solution would be to hook in way late (template redirect, for example), do your conditional check. If it passes, include (or require) a file that contains the stuff needed.
<?php
add_action( 'template_redirect', 'wpse30291_template_redirect' );
function wpse30291_template_redirect()
{
if( ! is_singular() ) return;
require_once( 'your-file.php' );
}
This is not going to work if your-file.php
contains functions hooked into things that happened earlier (eg. init
or wp
). But if your-file.php
contains things that, say, modified content (hooking in the_title
or the_content
, for instance) then it would be fine.
Related Posts:
- Plugin Form Submission Best Practice
- Plugin directory “Last Updated” not changed after initial commit?
- What is the recommended way to create plugin administration forms?
- Fatal error: Call to undefined function wp_mail()
- Does WordPress have an Browser Agent?
- How Do I Load My Action Earlier Enough?
- How to check WordPress website username and password is correct
- How to sync with plugins update after I have done manual optimizations?
- How to retrieve a value via get_option when the option_value is stored in a multi-dimensional array?
- I can’t find where a hook is being defined in a plugin – Easy Digital Downloads
- Filter on the_content ignores shortcodes
- Custom theme sufficient or custom plugin neccessary for this feature set?
- Check spam in custom form – akismet
- Add Admin Menu Inside Construct or Init
- get plugin directory url
- WordPress cron running twice
- How to create thumbnail of different files?
- PHP library that can merge stylesheet with inline style [closed]
- Admin-ajax.php appending a status code to ajax response
- comment_email hook doesn’t seem to work for comment editor field
- How can I add a field to make link nofollow to the WordPress Link Inspector Window?
- admin_notices not displaying in plugin
- How to get color name in PanelColorSettings in custom Gutenberg block?
- Get Objects While Deleting term
- Fetching the value of forms in WordPress AJAX
- Cannot redeclare function error on the same line
- js/css updating when making a plugin
- Subscribe to author?
- Append country to ‘pretty’ url but serve same page
- Set page template programaticlly in plugin
- Adding a brand column to WooCommerce Products
- How to use output buffering in WordPress hooked functions?
- Adding option to Gallery shortcode
- WordPress Search filter to remove possible script injections
- Plugin menu addition in multisite
- Mixing and Matching – Custom templates in a WordPress plugin
- Open Graph Object Debugger & url parameters – Page Not Found result
- How to get Metabox custom field to show checked if value is updated using post meta query?
- wp_schedule_event seems to be being added twice
- How to handle shortcodes through plugin
- How to build a fool proof AdSense revenue sharing model?
- Run a function when new image is uploaded in media library
- Setting up Version Control for WordPress plugin development
- Ajax submit result opens in admin-ajax.php
- get author of published post
- Error passing post_content to function
- How to access all array values from do_action_ref_array()?
- Add a check box in Menu Settings
- How to add custom post widgets as tags into wordpress
- How to register my code as a plugin
- What might be the reason of Couldn’t fetch mysqli_result on another domain?
- How to get terms for taxonomy
- If $var is empty, return 404.
- Listing wordpress users with a search function
- Cannot stop wpautop from messing up my plug-in output
- Plugin won’t activate
- dbdelta failing with error: “WordPress database error Table ‘wp_2_myPlugin’ already exists
- Plugin could not be activated because it triggered a fatal error?
- Get cat parameter from admin-ajax
- Update product prices from remote file
- How to determine primary editor for a page/post
- Using wp_mail to send email?
- Which wp plugin can use Create, Edit and Delete Email address from WordPress Dashboard
- WPGut – Updating failed and shortcode?
- product-attribute-slug-is-too-long-28-characters-max
- Limit get_next_post to posts from the same author
- Show list of categories that has posts with different taxonomies
- “add to cart” links css class “ajax_add_to_cart” doesn’t show in woocommerce in widget sidebar
- how to create a shortcode from a variable in plugin
- Any way, hook to add content right before the “read more” link?
- Error Connecting to Database WHEN Installing WordPress on XAMPP [Tried All the Usual Stuff] (Pics Included)
- How do I ensure I can loop through every enqueued script and CSS?
- What is the source of the $post_id in a hook argument?
- WordPress Fatal error: Uncaught Error: Call to undefined function dbDelta()
- WordPress use template
- Adding body class in author page for custom role
- Plugins Settings page not updating
- TinyMCE 4.7.11 – Enable hidden WordPress core plugins? (referencing a wp-includes from plugin.php)
- Enqueue scripts based on site.
- My enqueue admin style function doesn’t work because of ?=ver
- Use content filter on the post that is password-protected
- WordPress filter custom posts by multi terms of of a taxonomy
- foreach argument to get specific file types getting too many returns
- Query only title/field/featured media of posts [closed]
- To remove rendering of menus and header, plugin or theme?
- How can I give access to my plugin sections in admin?
- Filter the_content() to add custom figure tags
- Making plugin output customizable
- Return all roles, including custom roles
- Mapping multiple URLs to same page
- Installing plugins on installation/activation
- Loading jQuery library from WordPress admin
- How to display .ptm file in my WP site without JAVA
- How to replace content of a block in and re-render on change?
- extending a core block doesn’t work inside the editor
- register_activation_hook doesn’t execute without add_action(‘init’,’some-function’)
- Getting similar posts by custom field value
- Does WP REST API cache internally executed (rest_do_request) requests?
- Trouble Importing whatsapp-web.js in a WordPress Plugin Development
- ‘useSate’ error when using React on the frontend in custom block plugin