Notifications
Clear all

[Closed] Get forum / topic title

5 Posts
2 Users
3 Likes
2,779 Views
Posts: 393
Topic starter
(@anonymous3542)
Honorable Member
Joined: 7 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
Posts: 393
Topic starter
(@anonymous3542)
Honorable Member
Joined: 7 years ago

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

Robert
Posts: 10499
Admin
(@robert)
Support Team
Joined: 8 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' );
Posts: 393
Topic starter
(@anonymous3542)
Honorable Member
Joined: 7 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

Posts: 393
Topic starter
(@anonymous3542)
Honorable Member
Joined: 7 years ago

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