Archived topic
How do I add a condition to a hook element?
11 replies · Started by Carsten on May 6, 2020
Hi there
I need to wrap a custom link like this bp_after_profile_content into a condition like this, to display only on members own profile. But how do I add a condition to a hook element?
if ( bp_is_my_profile() ) {
// echo edit links here
}
Thanks
Hi there,
You would do exactly what your example is showing, you just need to open and close PHP:
<?php
if ( bp_is_my_profile() ) {
// echo edit links here
}
?>
Then make sure the "Execute PHP" option is checked.
There must to be something wrong with this markup, changes do not kick in?
<?php
if ( bp_is_my_profile() ) {
echo "bp_after_profile_content"; // echo edit links here
}
?>
Is "Execute PHP" enabled? That code should output that echo in that hook position as long as bp_is_my_profile() is true.
Yes, “Execute PHP” is enabled,
This is the outcome of the code, which have been added in two elements, which is plain text, and is displayed on all profiles
bp_is_my_profile() is true:
bp_is_my_profile
Is the current page part of the profile of the logged-in user?.Description
bp_is_my_profile();
Will return true for any subpage of the logged-in user's profile, eg http://example.com/members/joe/friends/.
It looks like it's working? I'm seeing the "bp_after_profile_content" text on the page.
The below line will do nothing but output that text. If you want someone else, you need to replace the text with the necessary output:
echo "bp_after_profile_content";
The hook is working correctly, I can see now, that I'm mixing things up, I’m outputting a hook, not the content, the div inside of the element, that I want:
<div class="item-list-tabs no-ajax">
<ul>
<li id="subnav"><a id="1" href="https://domain/members/me/profile/edit/group/1/">Profil</a></li>
<li id="subnav"><a id="8" href="https://domain/members/me/profile/edit/group/8/">Profileinfo</a></li>
<li id="subnav"><a id="12" href="https://domain/members/me/profile/edit/group/12/">Readmore</a></li>
<li id="subnav"><a id="5" href="https://domain/members/me/profile/edit/group/5/">Check in</a></li>
</ul>
</div>
In that case, you'd do this:
if ( bp_is_my_profile() ) {
?>
<div class="item-list-tabs no-ajax">
<ul>
<li id="subnav"><a id="1" href="https://domain/members/me/profile/edit/group/1/">Profil</a></li>
<li id="subnav"><a id="8" href="https://domain/members/me/profile/edit/group/8/">Profileinfo</a></li>
<li id="subnav"><a id="12" href="https://domain/members/me/profile/edit/group/12/">Readmore</a></li>
<li id="subnav"><a id="5" href="https://domain/members/me/profile/edit/group/5/">Check in</a></li>
</ul>
</div>
<?php
}
Thanks a lot, unfortunately it breaks my site, can there be a syntax error somewhere in this code, are the php tags ?> <?php correct?
Yes, this would be the full code:
<?php
if ( bp_is_my_profile() ) {
?>
<div class="item-list-tabs no-ajax">
<ul>
<li id="subnav"><a id="1" href="https://domain/members/me/profile/edit/group/1/">Profil</a></li>
<li id="subnav"><a id="8" href="https://domain/members/me/profile/edit/group/8/">Profileinfo</a></li>
<li id="subnav"><a id="12" href="https://domain/members/me/profile/edit/group/12/">Readmore</a></li>
<li id="subnav"><a id="5" href="https://domain/members/me/profile/edit/group/5/">Check in</a></li>
</ul>
</div>
<?php
}
?>
Perfect, I must say that the discovery of the power of elements, really takes my development to a new level!
Thanks a lot for your impressive work on this great theme.
Regards
Carsten
Glad I could help :)