WordPress.org

Ready to get started?Download WordPress

Forums

How Do I Target All Posts Using Hooks? (2 posts)

  1. poname84
    Member
    Posted 1 year ago #

    I do not want to use a plugin for this. I want to have as much control as possible so I'd like to hard code it using hooks. I'm using Headway with my own child theme.

    I did extensive research yesterday and still could not find the answer. It seems like either I missed something very crucial, or unbelievably, there has not been a tutorial on the web or in the codex to globally target all posts (I'm going with the former).

    My question is this:

    I'd like to add social sharing buttons to every post on my website. How would I target every post (blog page, single post page, etc.) using a hook in order to insert these icons? I know how to target and style with css so that won't be an issue for me.

    Here is what I think I know now:
    *I would drop this code into functions.php
    *It would be using hooks with links to the icons included

    Where do I go from here?

    Thanks,
    Dan

    P.S. I already posted this in the parent forum without realizing that it was in the wrong place.

  2. catacaustic
    Member
    Posted 1 year ago #

    I wouldn't use hooks or anything to add these to the post/page content. I'd add these in my themes template file/files - and the best way is by creating your own function or template file to do this.

    By creating a function, as an example called social_icons() you can just write <?php social_icons(); ?> anywhere that you want the icons displayed in your template files.

    If the icons aren't going to change much (they probably shouldn't) I'd create a new template file and use get_template_part() to include that in your theme files where it's needed.

    The biggest advantage of both of these methods is that if anything ever does happen to change you only ever need to update one piece of code in one place. By adding this to each post/page content you'd have to update ever post/page every time there's any change at all.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.