New answers tagged

0

There are two functions added in the header.php and footer.php files wp_head() and wp_footer(). If you do not use get_header() or get_footer() the two function will not be added into your tempalte files. Lots of plugins and themes use those to functions to add in styles and scripts. All you would need to do is add those functions into your template where ...


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 ...


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(...


1

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


0

It's a bad idea because woocommerce has about 20 translations. In that case you have to translate the modified text domains, or if they don't the 50% of woocommerce will be english, but I want spanish.


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

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( $...


0

Assuming that you are talking about a custom post type the answer is right in the codex. Generate a template called single-{post-type}.php and WP takes care of the rest.


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 ...


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 ...


0

I'd say there are roughly two approaches to this: 1 Use get_template_part(). This is the normal way of inserting pieces of code into a template. However, you cannot pass arguments to this function. So if you want to repeat ten pieces of code with small variations, you cannot tell get_template_part what the variations are. It is possible to get around this: ...


0

You have no need callback function. Only reverse_top_level: true is find for what you want to do. Just remove 'callback' => 'custom_comments_callback', from your array. <?php wp_list_comments(array( 'reverse_top_level' => true, 'avatar_size' => 50, 'reply_text' => 'Reply to this comment' )); ?>


0

{{ post.thumbnail.ID }} will get you the image ID, but to answer what you're after.... <img src="{{ post.thumbnail.src('medium_16x9') | default( Image(1234).src('medium_16x9') ) }}"> Reference


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( $...


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 ...



Top 50 recent answers are included