Archived topic
Hook in the Content Area
8 replies · Started by Oppo Gene on April 4, 2023
Hi there, I want to place hook in and below the content area
Thank You
Looking Forward
Hello there,
Try adding this snippet:
add_shortcode('portable_hook', function($atts){
ob_start();
$atts = shortcode_atts( array(
'hook_name' => 'no foo'
), $atts, 'portable_hook' );
do_action($atts['hook_name']);
return ob_get_clean();
});
add_filter( 'the_content', 'insert_custom_hook', 20 );
function insert_custom_hook( $content ) {
global $post;
$inserted_hook = do_shortcode('[portable_hook hook_name="after_post_content"]');
if ( is_single() && ! is_admin() ) {
return $content . $inserted_hook;
}
return $content;
}
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
After activating this PHP snippet on your site, you can hook things at the end of the content using after_post_content hook.
this will also works with in the content area?
That hook is added directly after the Content.
You can use the same Hook to add your advertisement.
If we want to place ads within the content area, is it possible so?
also check this
Do you mean after these?: https://share.getcloudapp.com/Z4un1EOd
yes, but no after 2 files after some more no of files
Perhaps you can try reaching out to the plugin you used for these and ask if it's possible to add a hook after every 2 files.