Notifications
Clear all

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

9 Posts
4 Users
1 Likes
609 Views
newuser20
Posts: 5
Topic starter
(@newuser20)
Active Member
Joined: 1 year ago

is there a hook to add content before comments area?

8 Replies
Chris
Posts: 1962
Admin
(@chris)
Support Team
Joined: 1 year ago

Hi @newuser20,

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

Reply
newuser20
Posts: 5
Topic starter
(@newuser20)
Active Member
Joined: 1 year ago

Hello @Chris

thank you for reply

i want a hook under the first post

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

Prominent Member
Posts: 774
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)

Reply
Chris
Admin
(@chris)
Joined: 1 year ago

Support Team
Posts: 1962

@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';
    }
});

 

Reply
newuser20
(@newuser20)
Joined: 1 year ago

Active Member
Posts: 5

@chris 

it working but the content appear in every page 

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

Reply
Chris
Admin
(@chris)
Joined: 1 year ago

Support Team
Posts: 1962

@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.

Reply
newuser20
Posts: 5
Topic starter
(@newuser20)
Active Member
Joined: 1 year ago

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

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

Support Team
Posts: 9737

@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';
}
});
Reply
Share: