Title: php template as php snippet
Last modified: August 5, 2020

---

# php template as php snippet

 *  Resolved [mitdrissia](https://wordpress.org/support/users/mitdrissia/)
 * (@mitdrissia)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/php-template-as-php-snippet/)
 * Hi, i want to add a snippet from a php template. Is this possible on a page basis?
   
   Why i want this is because the php template gets overwritten when i have a theme
   update.I don’t want to use a child theme because of speed performance.
 * The documentation can be found here:
    [https://docs.themeum.com/tutor-lms/developers/advanced-course-filter/](https://docs.themeum.com/tutor-lms/developers/advanced-course-filter/)
 * thank you
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fphp-template-as-php-snippet%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/php-template-as-php-snippet/#post-13216046)
 * It’s certainly possible. Here’s an example:
 *     ```
       // add the new template to the dropdown
       add_filter( 'theme_page_templates', function ( $templates ) {
       	$templates['advanced-course-filter.php'] = __( 'Advanced Course Filter' );
       } );
   
       // load the template when viewing the page
       add_filter( 'page_template', function ( $template ) {
   
       	if ( get_page_template_slug() === 'advanced-course-filter.php' ) {
       		$template = WP_CONTENT_DIR . '/advanced-course-filter.php';
       	}
   
       	return $template;
       } );
       ```
   
 * The only things you should need to change here are:
    1. `'Advanced Course Filter'` to whatever you want the name of the template to 
       be in the WordPress dropdown list.
    2. `advanced-course-filter.php` to the filename of the page template file.
    3. `WP_CONTENT_DIR` to the filesystem location of where you’ve stored the page 
       template file.
 * Hopefully this is what you’re looking for!
 *  Thread Starter [mitdrissia](https://wordpress.org/support/users/mitdrissia/)
 * (@mitdrissia)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/php-template-as-php-snippet/#post-13217693)
 * great to hear that this is possible. But will it load all resources on all pages
   or only on the page i specify?
    so it will not be overwritten after theme update?
 *  Thread Starter [mitdrissia](https://wordpress.org/support/users/mitdrissia/)
 * (@mitdrissia)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/php-template-as-php-snippet/#post-13217759)
 * 1.’Advanced Course Filter’ to whatever you want the name of the template to be
   in the WordPress dropdown list.
 * With WordPress dropdown list you mean when i assign template to the page correct?
   
   So i can leave it as same name.
 * 2. advanced-course-filter.php to the filename of the page template file.
 * If i use the same php file then wouldn’t it be overwritten after next theme update?
   
   please explain this part.
 * 3. WP_CONTENT_DIR to the filesystem location of where you’ve stored the page 
   template file.
 * What would be a good place to place the page template file in without being overwritten
   after update.
 * Sorry for all the questions but i allready got my fingers burned by losing a 
   complete customized page because of the overwriting part.
 * Thank you for your reply, I appreciate it
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/php-template-as-php-snippet/#post-13218146)
 * If you make a file called `advanced-course-filter.php` and put it directly in
   your site’s `wp-content` directory, then you should be able to use the code I
   posted unchanged.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘php template as php snippet’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

## Tags

 * [code snippet](https://wordpress.org/support/topic-tag/code-snippet/)
 * [php template](https://wordpress.org/support/topic-tag/php-template/)

 * 4 replies
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/php-template-as-php-snippet/#post-13218146)
 * Status: resolved