2

I want to add a header image via some custom HTML to the posts page but can't edit it with the pages menu in Wordpress. Is there a way to add the HTML in the specific PHP-File and which PHP do I have to pick?

1
  • You really need to be more specific. The PHP to edit depends on your theme. Try browsing your theme templates and find out where the header is added (probably in the file named header.php). There you can add your html.
    – cjbj
    May 17 '16 at 13:41
1

If you want to modify the main <header> output take a look at header.php. This file will be called before the other templates.

If you want to modify the template that is used to display your latest blog posts, index.php would be the file of choice.

Index.php is also the fallback template for any post object so you might want to let it as it is to avoid the special content being displayed on any other site.

You could conditionally hook into pre_get_posts and do your modifications there. You could create your own action hooks and fire them conditionally. There are many ways to achive modifications.

For Conditionals see

2

Look in your theme structure, if it has single-post.php or single.php you can edit it, it shouldn't change the pages (but keep a backup just in case)

If you don't have these, create it

alternatively, if you only want it to work for a certain type of post, create a custom post type (you can do it manually or using a plugin such as https://en-gb.wordpress.org/plugins/custom-post-type-ui/screenshots/). Then you will have a special post type file called single-posttype.php (posttype being the name of the post you've given).

Next step, copy the code of the standard post into single-posttyle.php and modify the header to suit you..eg. go to single-post.php / single-posttype.php, look for the header call and change it so that it calls header-custom.php rather than the original header

You might find this helpful: https://developer.wordpress.org/files/2014/10/template-hierarchy.png

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.