Using do_action() in loop
-
Hi,
How do I use
do_action()
inside a posts loop (query)?function my_custom_text() { echo 'Some custom text'; } add_action( 'custom_posts_content', 'my_custom_text' );
Currently my posts query is build with so called concatenation assignment:
$output .= '<div class="my-class">'; $output .= esc_attr__( 'Some text.', 'my-text-domain' ); $output .= '</div>'; return $output;
When adding the
do_action()
, “Some custom text” is echoed multiple times before the other content, instead of inside every post.$output .= do_action( 'custom_posts_content' );
When changing the
echo
toreturn
in the function, nothing happens.What am I missing here?
Guido
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Using do_action() in loop’ is closed to new replies.