Question

i have looked all day for an answer to this i have an assignment brief that requires me too add a guess the logo script to any home page of a Wordpress installation.

i understand how to use add_action do_action and add_filter, at the moment i am calling my function via the add_filter to the content. This works however it adds the script to every post. I need a filter / action to run my function after or before the posts e.g

My function
[post1]
[post2]
[post3]

at the moment it is displaying like so

[post1 | my function | post content]
[post2 | my function | post content]
[post3 | my function | post content] 

Thanks in advanced.

Était-ce utile?

La solution

You can use the loop_start and loop_end hooks. See the example below.

function myFunction() {
    //do something
}
add_action('loop_start', 'myFunction'); //Call your function before the loop
add_action('loop_end', 'myFunction');  //Call your function after the loop

You can also check for the home page using is_home() function inside myFunction().

Hope this helps.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top