Questions tagged [template-include]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
2 answers
49 views

Why does get_post() return the latest post inside template_include before doing anything

Assume all the code below is in a theme's function.php If I add get_post() at the top, It'd get null, which is totally expected since I'm not in the loop, or nothing has been done. But I add ...
Obed Parlapiano's user avatar
0 votes
1 answer
159 views

Replace wp_query with wp_user_query

I'm turning out some subscriber archives and singles (profile pages) in my plugin where I'd also included a 'user-single' template, included via template_include. I'm experimenting however with ...
Kevin Nugent's user avatar
0 votes
1 answer
22 views

Pull in an "Include" file based on a WordPress Category ID

Here's what I am trying to achieve: when a category page is loaded then, based upn the ID of that category, an "include" file is loaded. I believe that the below would work for some limited ...
Henry's user avatar
  • 983
0 votes
0 answers
26 views

Use TEMPLATEPATH for custom url

I have a code in below and as you can see I have a condition to read custom template for desktop and mobile. Now I want to use a custom url instead of a file.For example I want to include a page site....
akhbarejadid's user avatar
0 votes
1 answer
499 views

How to use template_include hook with form submission?

I'm writing a plugin that uses the template_include hook to use a custom template for a custom post type. This works with GET requests, but with POST requests, it 404s because the $post variable is ...
kloddant's user avatar
  • 119
0 votes
1 answer
105 views

template_include doesn't work with child theme

I am using this code and it works perfectly but it does not work if I activate the child theme how can I solve? add_filter( 'template_include', 'wpse_template_include' ); function ...
Vincenzo Piromalli's user avatar
0 votes
0 answers
46 views

How to include a page template and template part into my plugin

I am creating my first plugin with a template for the frontend. My current structure is: /my_plugin/views/page_templates I have 2 main issues I am trying to resolve Is this the best way to include ...
php-b-grader's user avatar
2 votes
1 answer
309 views

For custom templates, is it better to use `template_include` or `type_template`?

I saw a lot of questions about including custom views in Wordpress (I mean custom templates). There were many answers. Some people recommend using template_include and others recommend using ...
kanlukasz's user avatar
  • 484
0 votes
0 answers
29 views

Should I use include(_once) or require(_once) for loading php-file with customizer settings?

Should I use include, include_once, require or require_once to load my customizer.php file? That file has all customizer settings and code in it. What is your advice on this? The file is currently ...
ralphjsmit's user avatar
0 votes
1 answer
44 views

Should I use do_action in the header file?

I have a lot to add on the header file because of if/else condition. And it makes the file very messy. So, I have decided to include another file... So how to add it: Creating a function file and ...
webfuelcode's user avatar
1 vote
1 answer
3k views

Put CSS inside a PHP file and include it the right way

I want to put CSS inside a PHP file, because with that I can use 'conditional CSS', depending on the value of a customizer control. My idea is to create a new php file, somewhere in my theme ...
ralphjsmit's user avatar
3 votes
2 answers
1k views

Render a different post/template from within the template_include action?

I am working on a webinar plugin that uses a custom post type to display the webinar pages. Those pages could be register, thank you, countdown, live etc. depending on the visitors registration status ...
mikedavies-dev's user avatar
0 votes
1 answer
266 views

Include Template Based on User IP Address

I need to prohibit certain IP Address from visiting my wordpress site. Hence i have used below code in my child theme function.php add_action('template_include', 'restrict_user_access'); function ...
Prasanth R's user avatar
0 votes
0 answers
49 views

Redirect page to homepage, keeping URL

I'm creating a site where every page is really rendered on a single page - the homepage. I'd like to make it so page URLs - like /about-us/ - redirect back to the homepage, but keep the same URL (/). ...
W Biggs's user avatar
  • 103
1 vote
1 answer
34 views

How do I go about looping through a advanced custom field on a particular page inside of another page

I have one page lets call it page-home.php and I also have a page called page-custom-field.php I want to have a section of the first page where it loops through page-custom-field.php page and display ...
Anders Kitson's user avatar
0 votes
0 answers
1k views

How to add variables to a template

I am using a query argument detail to check if a custom template should be loaded. This works fine, but I also need to add some variables that can be accessed from within the template. Here I am using ...
Cyclonecode's user avatar
  • 1,154
1 vote
1 answer
344 views

Why isn't template_include working with AMP correctly?

Before you ask I have looked around the similar questions to find a resolution but I couldn't find one that worked. Ive tried the permalink option several times, There is nothing in my htaccess file ...
DonnyDev's user avatar
1 vote
1 answer
133 views

Content vs Template on custom post

I just wrote a custom post (suppliers) as a plugin (with meta content) that works great. I've also created a template page (single-suppliers.php) within the same plugin to display the data. I wrote it ...
JasCav's user avatar
  • 137
0 votes
1 answer
389 views

Why is WP template_include overwritting all templates rather than specified page?

I have created a custom plugin for WP that has an action that includes a template via template_include as shown here: public function __construct( $wp_custom_plugin, $version ) { $this->...
codacopia's user avatar
  • 121
1 vote
1 answer
3k views

locate_template function - File not getting included

$locate = locate_template( 'widgets/the-post-widget.php' ); I am using the above path and method to include a file in functions.php, but that is not happening. The file doesn't seem to include. Am I ...
WordCent's user avatar
  • 1,867
0 votes
1 answer
194 views

WP overwrites my setup_postdata() setup

I'm trying to display under a (very) custom URL a post in a template of my choice. My post's ID in this example is 1008 and my template name '/singles/lecture.php'. Im the future will check the URL ...
Picard's user avatar
  • 1,145
1 vote
1 answer
679 views

Is it safe to include a javascript file in a template's php file?

I want to include some jquery plugin files to my wordpress multisite install. My solution involved creating a specific template file for the pages that required these jquery plugins. Below is the line ...
user104867's user avatar
0 votes
3 answers
273 views

php include returns 1 after content

I'm using a customized wordpress loop which allows me to style the post a certain way after a certain amount of post. For example, The first three post will be styled the same, the next 4 post will ...
Terrell Anderson's user avatar
0 votes
1 answer
36 views

require happens out of order

I have a page template that is including another file via require_once. I want this included file to have access to the $post object but it can't find it. So I ran something like this to see what's ...
Esaevian's user avatar
  • 111
0 votes
1 answer
2k views

wp_mail: Using file_get_contents to include template in message

I want to use a template as the message in an email which I send with wp_mail. But I get the error: "failed to open stream: No such file or directory". add_filter( 'wp_mail_content_type', '...
Galivan's user avatar
  • 243
2 votes
1 answer
938 views

WordPress rewrite rules for state and city

I'm building a site where every state and city in the US has a landing page. I have a database of every city, state, and zip code, set up as a custom post type in WP. Here's what I've done ...
Jack Arturo's user avatar
1 vote
3 answers
2k views

Get template name by full URL

Is There Any Way to get the template Name By full URL for example If the full url is www.example.com/hello-world I need a function that return the template name (page.php) I know that WordPress ...
mahmoud sami's user avatar
4 votes
1 answer
2k views

Custom Endpoint Gives 404 Header

I'm trying to write a general endpoint that loads a template. It works as expected with the small exception that the returned header is 404 - Page not Found. Am I missing something in my rewrites? ...
Howdy_McGee's user avatar
  • 20.6k
0 votes
0 answers
2k views

Using require_once for parent-directory not working but is working in sub-directories

I'm building a custom theme and I'm attempting to use require_once __DIR__ . '/templates/variables.php' in my footer.php file, to keep from repeating code that contains variable information... I keep ...
Corey's user avatar
  • 113
3 votes
2 answers
1k views

template_include for search.php makes Wordpress think its on the home page

I have a custom tag-search feature, which allows people to search multiple tags to return relevant posts. Say they want to see posts that are tagged both 'Wordpress' and 'Tutorials'. I'm using the ...
Shawn Wernig's user avatar
0 votes
2 answers
147 views

unexpected T_FUNCTION in plugin template [closed]

I have a plugin I have developed for a client which works fun on my server but doesn't work on theirs, they are on godaddy so I am guessing it's an issue with their PHP version? add_filter('...
Gareth Gillman's user avatar
0 votes
1 answer
147 views

Template Include crashing browser

I am creating a plugin which requires use of custom templates so using the following code to use the templates: add_filter('template_include', 'hhavideo_set_template'); function ...
Gareth Gillman's user avatar
2 votes
1 answer
544 views

template_include not loading -instead goes to index.php

I have the following code: <?php function ex_rewrite_rules(){ //discography query variable rewrite add_rewrite_rule( 'artists/([^/]+)/discography/?$', 'index.php?album_artist=$matches[1]&...
nelson's user avatar
  • 97
0 votes
1 answer
128 views

Theme parts path location dump

Few months back I was working on customizing theme that I was assigned to. I remember that I used some function or define something in the config or theme functions file and than it displayed debug ...
Joe's user avatar
  • 3
1 vote
1 answer
74 views

problem including page template

I am creating a one page wordpress site. The code I am using does work but for some reason it will not include page templates. It only gets the content from the page editor but will not get the custom ...
Jamie's user avatar
  • 1,363
1 vote
0 answers
57 views

A include_template Question

Right now I am building virtual pages on a wordpress install. I use the include_template hook to add some logic that checks for a 404 page & some regex to look for a specific pattern. This seems ...
user1837671's user avatar
1 vote
5 answers
4k views

Link to file in plugin directory from wordpress template?

I know that plugins and theme files should be kept separate but for for internal use I need to do it this way. In my themes header.php file I want to include a php file which just contains html, ...
Damainman's user avatar
  • 253
1 vote
2 answers
901 views

template_include filter does not render the custom template

I created a plugin that will render a shortcode that is entered to a page. This Shortcode shall override the theme's page template and use the one that I included on the plugin Here's my code: api....
user37449's user avatar
32 votes
3 answers
34k views

Is there any way to use get_template_part() with folders?

I'm wondering if there is any way to use get_template_part() with folders? My main folder has a lot of files now because I put every re-usable element in a separate file. I'd like to put them in ...
Paul's user avatar
  • 2,150
11 votes
2 answers
8k views

Use template_include with custom post types

I want to check for an appropriate template in the theme folder before falling back to the file in my plugin directory. Here’s my code: add_filter('template_include', 'sermon_template_include'); ...
Jack's user avatar
  • 113
1 vote
1 answer
3k views

How to check if txt file exists inside template folder?

I have a folder inside my theme where I hold some txt files which I am including in a theme. The problem is that before including txt file I need to check if it does exist. I fail checking it the ...
Alex's user avatar
  • 305
17 votes
3 answers
1k views

Methods of Integrating Plugin Data with Themes

I would like to get some opinions regarding the best practices for developing WordPress plugins that provide theme integration. In order to make sense as I ask this question, let me start with an ...
tollmanz's user avatar
  • 5,500