What should I put on my index.php?

index.php is shown whenever wordpress doesn’t find an appropriate page template. Generally people use it as the template for their site’s blog. If you are absolutely sure that it will never be reached, you can leave it empty. Just make sure you have that file present, otherwise the theme will not work As a personal … Read more

How to Increment ID value within ACF Repeater Field Loop

Try using a “counter” variable for the loop maybe? <?php if ( get_field(‘ingredients-list’) ) { echo ‘<ul class=”ingredientsList”>’; $count=0; while ( has_sub_field(‘ingredients-list’) ) { echo ‘<li class=”ingredient” itemprop=”ingredients”> <label for=”check-‘. $count .'”> <input type=”checkbox” class=”check” id=”check-‘. $count .'”> ‘; if ( get_sub_field(‘quantity’) ) echo ‘<span class=”quantity”>’ . get_sub_field(‘quantity’) . ‘</span> ‘; if ( get_sub_field(‘measurement’) ) … Read more

Calling an image within the theme folder from inside a post/page?

I realize that this was posted about 7 months ago, but in case you’re still looking for a solution to this, add this to your functions.php file: /** * Add a shortcode for the current theme directory * @return string Current theme directory */ function yourtheme_get_theme_directory_uri() { return get_template_directory_uri(); } add_shortcode( ‘themeuri’, ‘yourtheme_get_theme_directory_uri’ ); Then … Read more

Change location of header.php and footer.php

It is not possible to override header/footer via hooks in respective get_header()/get_header() functions. However it is often overlooked that these function allow input and loading different headers. For example get_header( ‘nested/header’ ); will look for header-nested/header.php in theme’s folder. It’s kind of a hack in regards to subdirectory use, but it works. 🙂

ACF – Theming Flexible Content

And to add to previous answers, you can not only use get_template_part, but also use it’s second param and combine it with ACFs get_row_layout. So let’s say that somewhere in your template is: <?php while ( have_posts() ) : the_post(); ?> <article> … SOME CODE <?php while ( have_rows( ‘YOUR_FIELD_NAME’ ) ) : the_row(); ?> … Read more

get_template_part returns NULL

As the codex page of get_template_part() says: get_template_part doesn’t return a value and doesn’t warn if it fails to find a matching template file. Additionally: If you want to hear about failures, use: <?php assert( “locate_template( array(‘$name-$slug.php’, ‘$name.php’), true, false )” ); ?> So no wonder you are get nothing back. One thing I’m seeing … Read more

How to create a wordpress template without using any page

You may use template_redirect action: add_action( ‘template_redirect’, ‘wpse131387_template_redirect’ ); function wpse131387_template_redirect( ){ if ($_SERVER[‘REQUEST_URI’] == ‘/some-template’) { global $wp_query; $wp_query->is_404 = false; status_header(200); include(dirname(__FILE__) . ‘/some-template.php’); exit(); } }