Remove Freshness Date In Forum & Topic Pages
-
Hi everyone,
I want to remove the last post date from my bbpress forum and topic pages:
I want only this to show up:
Freshness
[AVATAR IMAGE] Username
Basically i want to get rid of the date. I tried using CSS with this code:
li.bbp-forum-freshness a,
li.bbp-topic-freshness a{display: none;
}
But it hides both the date and the username.
So, how can i hide only the date and leave the username?
Please help.
-
Can you get more specific with your CSS? By that, I mean just targeting the date instead of the whole freshness block. For example, I see on my bbPress installation that the date in the forum freshness is in a child div of li.bbp-forum-freshness, which in CSS would be div.forums-topic-datetime.
If you are more comfortable with PHP and WordPress development the forum and topic freshness links do have filters:
bbp_get_forum_freshness_link
bbp_get_topic_freshness_linkBoth filters pass the link html and the forum/topic id to your callback function. You could then hook to these filters, and simply have your filter callback return an empty string.
I tried to use div.forums-topic-datetime with display: none; but i can’t get it to work. Can you please post the whole code? I’m fairly new to CSS.
Regarding the PHP filers…I’m not sure how to do this either. Any help would be greatly appreciated.
Managed to make it work using this 2 functions:
function remove_bbpress_forum_freshness_date() {
return '';
}
add_filter('bbp_get_forum_freshness_link', 'remove_bbpress_forum_freshness_date');function remove_bbpress_topic_freshness_date() {
return '';
}
add_filter('bbp_get_topic_freshness_link', 'remove_bbpress_topic_freshness_date');But now i’m thinking to do something else. Instead of removing the date i want to rename it to something like “View Post”. The freshness date already links to the last post by default so i just want to rename it.
Do you know how can i do this?
Anyone?
The filter passes the anchor tag HTML and the forum_id to your callback. To do this, you’ll have to change your filter, like so:
function remove_bbpress_forum_freshness_date( $anchor, $forum_id) {
}add_filter('bbp_get_forum_freshness_link', 'remove_bbpress_forum_freshness_date', 10, 2);
So you can see that your filter callback would be passed the anchor and the forum id.
In the bbPress code, it basically just gets the link for the forum, gets the title for the forum, gets the last active time for the forum, and constructs an anchor tag from all this information.
In your filter callback, you can do like is done in the bbPress code:
$forum_id = bbp_get_forum_id( $forum_id );
$active_id = bbp_get_forum_last_active_id( $forum_id );if ( empty( $active_id ) ) {
$active_id = bbp_get_forum_last_reply_id( $forum_id );
}
if ( empty( $active_id ) ) {
$active_id = bbp_get_forum_last_topic_id( $forum_id );
}if (bbp_is_topic( $active_id ) ) {
$link_url = bbp_get_forum_last_topic_permalink( $forum_id );
} elseif ( bbp_is_reply( $active_id ) ) {
$link_url = bbp_get_forum_last_reply_url( $forum_id );
}
As you can see, this code gets the ID of the last active item in the forum, be it topic or reply. It checks to see if the last active item was a topic or reply, and gets the appropriate url using the appropriate function.
With the url, you can then construct an anchor tag, and the link would say “View Post” (or “View Topic” if you want to get specific). Then you would return that from the filter callback.
For topics, it’s much easier since the last active will only be replies. The way you set up the filter and callback will be the same, just replacing forum with topic. To get the url, for View Post, do this:
$link_url = bbp_get_topic_last_reply_url( $topic_id );
In the code, it checks this to see if there have been any replies:
$time_since = bbp_get_topic_last_active_time( $topic_id );
if ( empty( $time_since ) ) {
// there are no replies, you can return "No Replies"
} else {
// make anchor tag linking to "View Post"
}I hope this clears things up a bit for you to try it yourself.
@rsanchez1 Thanks a lot. Your post made me even more confused at first because i’m new to WordPress and PHP but after reading it a couple of more times and actually implementing what you said it made sense and i managed to get it to work.
I used this code (please look at it and let me know if there are any errors):
————————————————————-
function remove_bbpress_forum_freshness_date( $anchor, $forum_id) {
$forum_id = bbp_get_forum_id( $forum_id );
$active_id = bbp_get_forum_last_active_id( $forum_id );if ( empty( $active_id ) ) {
$active_id = bbp_get_forum_last_reply_id( $forum_id );
}
if ( empty( $active_id ) ) {
$active_id = bbp_get_forum_last_topic_id( $forum_id );
}if (bbp_is_topic( $active_id ) ) {
$link_url = bbp_get_forum_last_topic_permalink( $forum_id );
} elseif ( bbp_is_reply( $active_id ) ) {
$link_url = bbp_get_forum_last_reply_url( $forum_id );
}return "View Post";
}
add_filter('bbp_get_forum_freshness_link', 'remove_bbpress_forum_freshness_date', 10, 2);
——————————————————–
function remove_bbpress_topic_freshness_date( $anchor, $topic_id) {
$link_url = bbp_get_topic_last_reply_url( $topic_id );
$time_since = bbp_get_topic_last_active_time( $topic_id );
if ( empty( $time_since ) ) {
return 'No Replies';
} else {
return "View Post";
}}
add_filter('bbp_get_topic_freshness_link', 'remove_bbpress_topic_freshness_date', 10, 2);
———————————————————-
I have one more question. I gave this more thought and i think it would be better if i replace “View Post” with the post’s title on the forums page(not topics).
To do this is have to change the first function above.
Any ideas how should i change the code to return the post’s title instead of View Post?
Thank you for your help. It’s very much appreciated.
Hey i love to comment i want say honestly all the post is awesome!!!!!
thanks for your helpful shareI would also like to know how you would change it to be the posts title instead.
Any ideas?
@allenpayne It seems i’ve even more a beginner with this. I added your code above to my functions php and just got errors. What am I missing?
I’m also trying to figure out how to change bpress_forum_freshness_link() to output the Topic Name inside the link tag in replacement of the ‘freshness’ time.
Anyone have an update on how to do this? The internet is absent with a solution for this, would be awesome to have something!
- You must be logged in to reply to this topic.