WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Head code for "Posts page"? (18 posts)

  1. Jon33221
    Member
    Posted 2 years ago #

    I'm trying to put some code in the <head> portion of a website, and have been using the "Enhanced Header / Footer Injections" plugin to do it easily. It had been working well until I created a blog page rather than a static page. I can edit the header.php file found in the theme folder, but any edits I do there only show up on static pages. It seems that blog pages use a totally different file (or maybe it's just a condition that is set somewhere?) to show the header. What can I do about this?

  2. Gary Darling
    Member
    Posted 2 years ago #

    <head> and header are two different things - the head comes before the body of a document and contains the title, links to stylesheets and javascript, and all sorts of things needed to render the page properly. The header of a page appears inside the body tag and usually contains your site name and navigation.

    What sort of code are you trying to insert?

  3. Jon33221
    Member
    Posted 2 years ago #

    Yeah, I'm talking about the <head> section. I've realized that the code actually does work on the blog page and static pages. The thing that doesn't work is using the is_page_template function as a condition to identify the blog page (I only want to add the code to the blog head section). Do you know of a better function I can use?

  4. Gary Darling
    Member
    Posted 2 years ago #

    Use is_home()

  5. Jon33221
    Member
    Posted 2 years ago #

    I will try when I'm back in front of my computer, but I'm not sure that'll work because the front page on my site is static. The blog part is linked to from that page.

  6. Gary Darling
    Member
    Posted 2 years ago #

    There is a tag for that too, is_front_page() See:
    http://codex.wordpress.org/Conditional_Tags#The_Main_Page

  7. Jon33221
    Member
    Posted 2 years ago #

    It worked! I had tried dozens of ideas and skipped the one that was under my nose the whole time. Thank you so much!

  8. Gary Darling
    Member
    Posted 2 years ago #

    Glad to here, can you mark this as resolved?

  9. chriscarvache
    Member
    Posted 2 years ago #

    I've been thinking of adding options to add code to the 'special' pages.

    Of them would include

    • 404 Page
    • Home Page
    • Front Page
    • Archives Pages
    • Custom Post Type / Taxonomy Pages

    Any suggestions?

  10. chriscarvache
    Member
    Posted 2 years ago #

    Check out the new version! Lots of new features!

  11. Jon33221
    Member
    Posted 2 years ago #

    Sounds great! BTW, I love the plugin. Very simple and effective.

  12. Dallape
    Member
    Posted 2 years ago #

    Hello,
    Enhanced Header / Footer Injections is great plug in, but I need a tiny modification. I will try to explain. The code is now showin above the header.php, and I need under it.

    see screenshot
    http://i1119.photobucket.com/albums/k640/vaz2108/Untitled-2.jpg

    How to doo that?

  13. chriscarvache
    Member
    Posted 2 years ago #

    Dallape,

    The plugin isn't designed to work the way you suggest. The code is injected into the <head> part of the site (via the wp_head() action hook) or right before the end of the page, which would be just before the </body> tag (via the wp_footer() action hook).

    Sorry if there was any confusion as to what this plugin is aimed to accomplish!

  14. Dallape
    Member
    Posted 2 years ago #

    Thanks for reply. Can you suggest me some plug in for my needs?

  15. chriscarvache
    Member
    Posted 2 years ago #

    I am not aware of any plugins that will add code into your theme. However this would be an interesting feature to have in a plugin. Maybe the plugin would scan all the action hooks of the active theme and allow for code injection that way. Come to think of it, I think the Thesis theme has a plugin for it that allows for code injection.

    Anyway... If you're looking to add code into the theme you have a couple of options.

    • You can insert code directly into the theme by editing the active theme's files
    • Hopefully the theme will be well coded and will have and support several action hooks. If this is the case, all you have to do is find and reference the correct action hook and attach a function to it that will insert your code. Check out this function and its surrounding resources for an idea of how to do this. http://codex.wordpress.org/Function_Reference/add_action
  16. Dallape
    Member
    Posted 2 years ago #

    Anyway... If you're looking to add code into the theme you have a couple of options.

    You can insert code directly into the theme by editing the active theme's files

    I know that, but I need to insert code to homepage only. that is my problem :)

  17. Gary Darling
    Member
    Posted 2 years ago #

    Sounds to me like you could use the shortcode function, and use the is_front_page() function to qualify it.

    You can call the shortcode inside the editor like so: [my_shortcode_name], or if you need it outside the_content(), insert it in index.php like so: <?php echo do_shortcode( '[my_shortcode_name]' ) ?>

    index.php is your home page if you use blog posts as your front page (in Admin > Settings > Reading)

  18. Dallape
    Member
    Posted 2 years ago #

    I created new page template and, instead of <?php get_header(); ?>, I copied all content from header.php file and add code that I needed.

Topic Closed

This topic has been closed to new replies.

About this Topic