Skip to:
Content
Pages
Categories
Search
Top
Bottom

BuddyPress – Hide Profile Fields when blank


  • jcfromkc
    Participant

    @jcfromkc

    There’s an article about this topic that was marked Resolved, but the author did not reveal the actual solution.

    Only Display Custom Field if not empty

    I’m using the front.php template to customize the members profile page. On the members profile page, I’m trying to hide all Profile Fields that are empty.

    I’ve tried the code outlined in the referenced link with no luck. That post is about 4 years old so I don’t know if the information is the most up to date. When using the referenced code, I can’t get anything to show up on the page.

    Can someone please point me in the right direction?

    Thx, JC>

Viewing 1 replies (of 1 total)

  • jcfromkc
    Participant

    @jcfromkc

    I’m actually trying to hide the DIV and the empty Profile Field within the DIV. I’ve come up with this so far. I’ve created a file called hide-empty-profile-fields.js and enqueued the script.

    $(document).ready(function() {
         str = $('div.profile-page-location').text();
       if($.trim(str) === "") {
         $('div.profile-page-location').hide();
       }   
         str = $('div.profile-page-status').text();
       if($.trim(str) === "") {
         $('div.profile-page-status').hide();
       }  
        str = $('div.profile-page-zodiac').text();
       if($.trim(str) === "") {
         $('div.profile-page-zodiac').hide();
       }
        str = $('div.profile-page-occupation').text();
       if($.trim(str) === "") {
         $('div.profile-page-occupation').hide();
       } 
        str = $('div.profile-page-website').text();
       if($.trim(str) === "") {
         $('div.profile-page-website').hide();
       }
       
    });

    It works, but it’s not optimal. Using this method, the empty fields do not become hidden until the page is fully loaded. This causes a weird shift to occur upon page load.

    Still working on this.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar