Notifications
Clear all

Get forum / topic title

5 Posts
2 Users
3 Likes
2,420 Views
Anonymous3542
Posts: 393
Topic starter
(@anonymous3542)
Reputable Member
Joined: 5 years ago

Hi @robert,

Is there a function that displays the forum or topic title ? I have a header on my community page that I would like to change to be the forum or post title dependant on the selection.

I thought I could use something like this, but it doesn't seem to work

function vComp4(){
$getwpforotitle = $post['title'];
if(empty($getwpforotitle))
{
$getwpforotitle = "Title is empty";
}
return $getwpforotitle;
}
add_shortcode( 'wpforo-get-title', 'vComp4' );
4 Replies
Anonymous3542
Posts: 393
Topic starter
(@anonymous3542)
Reputable Member
Joined: 5 years ago

To clarify, I'm looking for the PHP variable of "wpforo-title"

Reply
Robert
Posts: 9327
Admin
(@robert)
Support Team
Joined: 6 years ago

I'm sorry but there is no an easy way do do this. I'd recommend this code, it may work.

function vComp4(){
if( is_wpforo_page() ){
if( wpfval(WPF()->current_object, 'topic', 'title') ) {
$title = WPF()->current_object['topic']['title'];
} elseif( wpfval(WPF()->current_object, 'forum', 'title') ) {
$title = WPF()->current_object['forum']['title'];
} elseif( wpfval(WPF()->current_object, 'user', 'display_name') ) {
$title = WPF()->current_object['user']['display_name'];
} else {
$title = "Title is empty";
}
}
return $title;
}
add_shortcode( 'wpforo-get-title', 'vComp4' );
Reply
Anonymous3542
Posts: 393
Topic starter
(@anonymous3542)
Reputable Member
Joined: 5 years ago

Thanks @robert. I'll give this a try. If all else fails, there's always wp_title() and regex. A little clunky, but would do the job I expect - just not very efficiently

Reply
Anonymous3542
Posts: 393
Topic starter
(@anonymous3542)
Reputable Member
Joined: 5 years ago

@robert just circling back here to let you know that this function works beautifully. Thanks very much

Reply
Share: