Hot answers tagged

4

Not sure the following solution is better than the solution in OP, let's just say is an alternative, probably more hackish, solution. I think you can use a PHP exception to stop WordPress execution when 'comments_template' filter is applied. You can use a custom exception class as a DTO to carry the template. This is a draft for the excepion: class ...


3

As @AlainSchlesser suggested to follow the route (and as non working things always bug me), I retried building a stream wrapper for virtual files. I could not solve it (read: reading the return values on the docs) on my own, but solved it with the help of @HPierce on SO. class VirtualTemplateWrapper { public $context; public function stream_open( $...


3

Solution: Use a temporary file – with a unique file name After a lot of jumps and crawling into the dirtiest corners of PHP, I rephrased the question to just: How can one trick PHP into returning TRUE for file_exists( $file )? as the code in core just is file_exists( apply_filters( 'comments_template', $template ) ) Then the question was solved ...


3

I have wrestled with this before and my solution was — it can knock itself out requiring file, as long as it doesn't do anything. Here is relevant code from my Meadow templating project: public function comments_template( \Twig_Environment $env, $context, $file = 'comments.twig', $separate_comments = false ) { try { $env->loadTemplate( $...


2

You won't lose any functionality. Get_header(), get_sidebar(), and get_footer() are basically shortcuts to include these templates. You can just include your templates using include or require. The only downside is that if you have custom templates, in a sub directory, you will have to specify the path of the say, the header.php file. If you use get_header(...


2

You really shouldn't be doing this. Functions belong in the functions file. Period. (Or perhaps in a separate functions file which you include in the main one) However, if you insist, you can drop functions in any template file you want, because PHP doesn't care. Actually you will need to include it in every template file where you want to call ...


1

If you're creating a theme you intend to distribute, using these functions gives users and other developers an opportunity to override the files with a child theme. It's just a predictable way to separate elements of your theme. Each of them also trigger an action with the same name, which may be useful to some. If you have some other template scheme, you ...


1

First, check the quotes: <?php echo do_shortcode('[enlarge_text small="A" medium="A" large="A" default_value="medium"]'); ?>


1

The 2nd part of the condition seems wrong basename( get_permalink() != 'sponsor-one') should be basename( get_permalink() ) != 'sponsor-one' Please check where the parenthesis ends. Also in your code if that is the only condition, then you can have an else statement instead of having another elseif.


1

If you want to change the single page page-{page-slug} is a good choice if you want the page template for specific page only and not multiple pages. Check out his custom page template for specific page If you are talking about custom post type We can use single-$posttype.php , here $posttype is your custom post type slug. WordPress template Hierarchy ...


1

The top answer (from 4 years ago) no longer works, but the WordPress codex has the solution here: <?php function add_posttype_slug_template( $single_template ) { $object = get_queried_object(); $single_postType_postName_template = locate_template("single-{$object->post_type}-{$object->post_name}.php"); if( file_exists( $...



Only top voted, non community-wiki answers of a minimum length are eligible