Use a use
statement:
add_filter( 'single_template', function ( $template ) use ( $name ) {
Or just pass all templates at once, and create just one function:
add_filter( 'single_template', function ( $file ) use ( $templates ) {
global $post;
if ( in_array ( $post->post_type, $templates ) )
return __DIR__ . "/{$post->post_type}.php";
return $file;
});
Related Posts:
- Create page template via functions.php?
- Change the “Show All” button in a WordPress Portfolio Filter
- Custom search results page not working with empty search
- I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
- How to show single category archive
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Removing “wpautop” (auto tags) only on certain pages?
- code is skipping a div
- Issues getting PHP to display in category pages
- Add filter when image is uploaded?
- Remove the first 5 characters of the_title and orderby that
- Remove a div from RSS feed
- Print last modified date only on posts
- How to add an arrow to menu items has submenus
- WordPress Gravatar filter is removing my custom attributes
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- Change title only in dynamic page
- Unique icons next to each WordPress menu item
- Secondary navigation menu on one page
- Enable custom logo upload if logo is not in header
- Change tinyMCE editor to allow marked content when pasting from Word
- Problem with login form
- How can I edit the content in index.php? [duplicate]
- Woocommerce Show Single Product on Homepage
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- how to show only specific category for a template
- Show a different code on front page to other pages
- Does wordpress templates always in files or in database?
- Alter required message using comment form api
- How to debug this search & replace strings snippet?
- Can’t print Yoast meta description into page template (syntax error, unexpected ‘.’) [closed]
- Using same variable names in files added with get_template_part()
- Hide Featured Image Meta Box on Editor Screen
- Add item to top of menu using a filter in functions.php
- PHP include is only working in certain places in my custom WP theme
- Use WordPress function in php file
- Adding wrapper elements in the_date() like in the_title()?
- How to get all author posts outside of author templates
- How to edit php code in WordPress Post file?
- Create a Blog Template Page
- Change page title from page using php via php executed from page/post itself
- Showing latest post without 301 redirect
- How to make modifications only to certain elements of an HTML string on the server-side?
- Override a function defined in wp-includes/comment-template.php
- WordPress template page name displayed on screen
- Is there a way to hook or call a custom woocomerce template that is not part of the default templates of woocommerce?
- single.php with different look by category
- Filtering a function’ output for a new continued function
- How to call multiple functions from multiple files into a WordPress page template [closed]
- Deleting Certain terms from appearing on the front end as links
- Content filter won’t work
- How do I define a lookup table that will work across all PHP elements of the template?
- persist a variable set in header.php all the way down to footer.php
- Function Reference Documenting Template Tags for use in Custom Theme Templates?
- Removing WordPress Footer -without access to PHP code?
- How to set a template with wp_insert_post
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- Why does the Woocommerce grouped template prints the unpublished products?
- Adding conditional text to a PHP Shortcode Template
- Warning: in_array() null given in PHP function
- Upload multiple files in randomly generated folder using wp_upload_bits
- Add meta tags to a custom header
- Ajax filter button display all posts
- How to append to an array and return the results in a filter?
- What’s a good way to allow overwriting files within a child theme if I want the same folder structure?
- how to display this functions?
- How to have different site identity logos on each page on Astra Theme [closed]
- is_page_template showing partial results
- Adding regular php file to site
- Advice on creating a WP Archive Template with Custom Taxonomy (get_term_meta)
- add_filter function concatenate string and locate_template function
- How to render a block from php template
- Template Loop – add switch case php
- How do I create a secondary version of the_content
- Override Admin menu icon
- Get the_content surrounded by instead of
- Post repeated when opening in overlay, how do I solve this? [closed]
- Custom query vars filters problem with pagination
- Filter by field with array value in ACF on WP REST API
- How to suppress template-parts in undescores?
- wrap a span tag around author’s post count
- Need help with pagination
- Get the name of menu item with wp_nav_menu
- How can I get “Previous” and “Next” to show in the navigation besides the links?
- Creating custom page template from existing PHP site
- Displaying content on posts page based on category
- update_post_meta() not saving data inside of save-post filter
- How do I query a single data value from the wp_metadata table?
- Conditional string comparison failing for basename/slug
- How to add aria role and schema markup to custom walker container
- Can I remove or edit an include() from a function with a filter?
- Dynamically adding filters
- Splitting the_content() by size?
- Gravity Forms merge tags in templates?
- Unable to render custom field after attempt to generate a list of recent post in page template
- How to add new CSS file to new PHP file
- Must filter functions receive all arguments passed to them?
- php loading different structure than source code
- pass html code to worpdress
- Some problems calling a function into sprintf() inside functions.php template file [closed]