Replies: 0
Hi.
Can someone explain what it means to “Hook function to an action”?
I have shortcode:
/* Prikazaće određeni broj riječi u postu, a zatim ispod obavijest da je tekst samo za VIP korisnike. */
function vip_part_text( $atts, $content = null ) {
if(is_user_logged_in()){
$content = apply_filters('the_content', get_the_content());
echo $content;
} else {
$more = '
<br>
...
<br>
<div class="advert" style="">
<div class="advert-page" style="">
<a style="" href="https://mllapan.com/pretplata/" target="_blank">
<div class="pretplata">Nemate dozvolu da pročitate ovaj članak u potpunosti.
<br>
Kupite doživotni VIP pristup svim člancima na stranici.
<br>
Uz VIP dobijate 24/7 pomoć na forumu također.
<br>
Za više informacija kliknite ovdje.
<br>
</a>
</div>
</div>
';
$content = apply_filters('the_content', get_the_content());
echo force_balance_tags( html_entity_decode( wp_trim_words( htmlentities( $content ), 100, $more ) ) );
}
}
The theme I am using shows content with action:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
/**
* Functions hooked into cera_single action
*
* @hooked cera_single - 10
* @hooked cera_grimlock_single - 10
*/
do_action( 'cera_single' ); ?>
</article><!-- #post-## -->
By theme developers as an answer, instead of usage:
<?php echo do_shortcode('[vip_part_text]'); ?>
to get shortcode influenced content, I should “Hook function to an action”.
I researched, and I realize it goes like add_action ($hook, $function, $priority), so kinda goes like:
add_action( 'cera_single', 'vip_part_text', 10 );
Instead of:
add_shortcode('vip_part_text', 'vip_part_text');
But my output is:
Content from vip_part_text.
Content from cera_single.
I guess this is actually how hooking works, as words say we hook something for soemthing else (existing).
What did he meant than when he said:
You can achieve this by using the cera_single action, simply hook your function to this action.