2

I'm working in a blog with a template of my own. When I link to a category page (i.e. mydomain.com/category/mycategory) Wordpress generates this HTML code just after the header.php:

<!-- HTML rendered by header.php -->

<!-- This 2 lines belong to index.php -->
<div id="primary" class="content-area">
  <main id="main" class="site-main" role="main">

<!-- HTML rendered by content.php -->
<header class="page-header">
  <h1 class="page-title">Category: My Category</h1>
</header>
<!-- .page-header --> <!-- this comment is also generated by content.php -->
<div id="post-292" class="grid-item">
  <!-- The rest of content.php -->
</div>

My content.php file is as follows:

<?php
/**
 * The template part for displaying content
 *
 * @package WordPress
 * @subpackage Twenty_Sixteen
 * @since Twenty Sixteen 1.0
 */
?>

<div id="post-<?php the_ID(); ?>" class="grid-item">
...

So the question is: where is the <header> tag generated and how can I customize it? I want to change the <h1> rendered content Category: My Category to be just My Category, for example.

Any help or guide is appreciated. Thanks in advance for your answers.

  • 3
    1) You might want to review the template hierarchy. 2) Could you post your header.php and possibly your index.php – Greg McMullen Aug 27 '16 at 15:11
  • WordPress works with themes and the themes are responsible for generating the html code. So a theme is activated and you want to override some template parts. To do that you have to create a child theme. – Laxmana Aug 27 '16 at 18:18
  • @GregMcMullen I've been reading the template hierachy and content.php is never mentioned. I added a category.php file in the same directory as index.php and now is reading that file. Could you post your comment as an answer? That's exactly what I needed and you gave me an excellent reference bibliography. Thank you so much. – Alvaro Pedraza Aug 28 '16 at 2:12
  • @AlvaroPedraza The comment that Greg provided solved your answer? – Ethan Jinks O'Sullivan Aug 28 '16 at 12:17
  • @AlvaroPedraza I've added and updated my answer for you. – Greg McMullen Aug 28 '16 at 18:34
3

Review the template hierarchy from the Codex to gain a better understanding of what files are read when. This will help you to understand what's called in what situation (tag/category/front-page/etc).

Content.php is never mentioned in the documentation as its not a part of the template hierarchy. Theme developers will use different file names and will reference them within the loop.

Most of the themes by Automattic use this technique to call the various parts to build out the content. Review your index.php, page.php, or post.php to see if content.php is used there.

| improve this answer | |
1
  1. Create another file form header.php and name it like header-{category-name}.php.
  2. Do your needed change on header-{category-name}.php.
  3. Then in your category.php call this file by get_header( 'category-name' ).
  4. If you don't have category.php file then create one by copying the archive.php template then follow the above instruction.

Follow those above steps and you'll get your desired result.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.