XF 2.2 xenforo api | code output on top?

szymme

Member
Hello xenforo, love you all. I hope you are a wordpress pro.

I installed Worpress and want to the show user id inside wordpress page. I use this code
<?php

require('forum/src/XF.php');
\XF::start('/hc');
$app = \XF::setupApp('XF\Pub\App');
$s = $app->session();
$uid = $s->get('userId');
if ($uid){
$finder = \XF::finder('XF:User');
$user = $finder->where('user_id', $uid)->fetchOne();
echo($uid);
}else{
echo 'guest';
}

?>

It works fine , love my life. But the problem is the userid is not showing inside the code block (with php snipped addon)....
The user id is printed on top of the page???? why??? i want to print it at the place i put the code block.#



ausgabe.png
 

kolakube

Well-known member
I can't speak much to the code you posted here, but you can use the solution I posted here since you use XFtoWP:


This grabs the XF user ID from the connected WP user account without needing to load XF into your site.

The user id is printed on top of the page???? why??? i want to print it at the place i put the code block.#
It depends on how this page was created. You may need to find the page template and edit it, or dynamically place it with a hook. If it's a page builder you can probably insert this content with a shortcode.
 
Top