General Discussions
5
Posts
2
Users
3
Reactions
3,124
Views
Jul 13, 2018 3:54 pm
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
Jul 13, 2018 4:43 pm
To clarify, I'm looking for the PHP variable of "wpforo-title"
Jul 13, 2018 7:54 pm
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' );
Jul 14, 2018 4:02 pm
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
Jul 15, 2018 3:56 pm
@robert just circling back here to let you know that this function works beautifully. Thanks very much