Notifications
Clear all

Script [Closed] is there a hook to add content before comments area?

9 Posts
4 Users
1 Likes
1,027 Views
Posts: 4
Topic starter
(@newuser20)
Active Member
Joined: 2 years ago

is there a hook to add content before comments area?

8 Replies
Chris
Posts: 3650
(@chris)
Famed Member
Joined: 3 years ago

Hi @newuser20,

You want a hook under the first post or under all replies?

Posts: 4
Topic starter
(@newuser20)
Active Member
Joined: 2 years ago

Hello @Chris

thank you for reply

i want a hook under the first post

4 Replies
Tutrix
(@tutrix)
Joined: 4 years ago

Noble Member
Posts: 1212
Posted by: @newuser20

i want a hook under the first post

You can use the Code Snippets plugin

create a new snippet with this code

add_action( 'wp_head', function () { ?>
<script>
jQuery(document).ready(function(){
jQuery( '<div class="content-after-first-post">Insert here the content to be displayed after the first post</div>' ).insertAfter( "#wpforo #wpforo-wrap .post-wrap.wpfp-first" );
});
</script>
<?php } );

add this to custom css (is only an example)

.content-after-first-post {
background: #f00;
color: #fff !important;
padding: 10px !important;
margin: 10px auto !important;
font-size: 18px !important;
}

Dashboard > Forums > Settings > Style (custom css)

Chris
(@chris)
Joined: 3 years ago

Famed Member
Posts: 3650

@newuser20,

Insert the bellow code in \wp-content\themes\ActiveTheme\functions.php file

add_action('wpforo_loop_hook', function($key){
    if( $key === 0 ){
        echo 'Your text Here';
    }
});

 

(@newuser20)
Joined: 2 years ago

Active Member
Posts: 4

@chris 

it working but the content appear in every page 

is there a way to show the content in post pages only?

Chris
(@chris)
Joined: 3 years ago

Famed Member
Posts: 3650

@newuser20,

Remove the Hook I gave you, Read this doc about theme customization:

https://wpforo.com/docs/root/forum-themes/theme-customization/

You need to customize wpForo theme to get the result you want.

Posts: 4
Topic starter
(@newuser20)
Active Member
Joined: 2 years ago

how to detect if current page is a post page and how to get all post information?

1 Reply
Robert
Admin
(@robert)
Joined: 8 years ago

Support Team
Posts: 10498

@newuser20,

Here is the code provided by @chris and modified to work only on the posts page:

add_action('wpforo_loop_hook', function($key){
if( function_exists('WPF') && WPF()->current_object['template'] === 'post' && $key === 0 ){
echo 'Your text Here';
}
});