How to check if searchform.php is being included as widget?

Check if searchform is included? The get_search_form() function (that should be used) uses locate_template(‘searchform.php’); to display the search form. The later returns (as you can see from its source) the template filename if one is located So if you’re just wanting to catch the default way, then you should simply test ‘searchform.php’ === locate_template( ‘searchform.php’ … Read more

Display HTML only if Custom Field has a Value

You can use the “get_sub_field” to test for the subfields. If nothing is returned and they are empty, it won’t show the content associated with the if statement. <?php if ( get_field(‘ingredients-list’) ) { echo ‘<ul class=”ingredientsList”>’; while ( has_sub_field(‘ingredients-list’) ) { echo ‘<li class=”ingredient” itemprop=”ingredients”>’; echo ‘<label for=””>’ . get_sub_field(‘quantity’) . ‘&nbsp; ‘; if … Read more

What is content.php file that is needed for Jetpack infinite scroll plugin?

There is no standard for a content.php in WordPress, that’s why you cannot find in the Codex. Some themes use it to render the post content. So instead of … while ( have_posts() ) { the_post(); ?><li <?php post_class(); ?>> <?php the_title( ‘<h2><a href=”‘ . get_permalink() . ‘”>’, ‘</a></h2>’ ); the_excerpt(); wp_link_pages(); ?></li> <?php } … Read more

Apply custom category template to subcategories

If a is the category slug, then following code would work – add_action(‘template_include’, ‘wpse129481_template_include’); function wpse129481_template_include($t) { // is category archive page if( is_category() ) { // current queried category id from queried object $child_id = get_queried_object_id(); // parent category object, getting it by slug. $parent_cat = get_term_by(‘slug’, ‘a’, ‘category’); // current category object, can … Read more

Page template not displaying

This is less of an answer and more of a kind of troubleshooting aid… Add this function to your project (probably functions.php) and then call it from the top of every template file in your theme… /** * Outputs the name of the file as an HTML comment for easy-peesy troubleshooting. * * @param string … Read more

Template for child pages / subpages

Here is a basic idea: Any page where the page parent ($post->post_parent) is 0, it means the page is a top level page. If any other value exists, the page is a child of another page. This value is the ID of the page that the specific page is a child to. With the above … Read more