Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolve] How to retrieve a direct path to cover image in cover-image-header.php


  • m1000
    Participant

    @m1000

    Hi

    Is possible to retrieve a direct path to cover image and display it in cover-image-header.php

Viewing 6 replies - 1 through 6 (of 6 total)

  • danbp
    Moderator

    @danbp

    i @m1000,

    try this (add to bp-custom.php):

    function bpex_cover_img_path() {
    	// Is the current page a user page?
    	if ( bp_is_user() ) {
    
    	$user_id = bp_displayed_user_id();	
    	
    	$attachment = bp_attachments_get_attachment( 'url', array( 'item_id' => $user_id ) );
    
    	$image_path = $attachment;	 
    	// output only if an attachment exist
    	if( !empty( $attachment ) ):
    		echo 'Cover image path: <code>'. $image_path .'</code>';
    	endif;
    
    	}
    }
    add_action( 'bp_profile_header_meta', 'bpex_cover_img_path' );

    m1000
    Participant

    @m1000

    Thanks!


    danbp
    Moderator

    @danbp

    You’re welcome. Can i ask why do you wanted this ? What is the purpose to show this link publicly ? By default, it is only used inside the background img css.


    m1000
    Participant

    @m1000

    I just what to use it inside img tag.

    BTW, why this code doesn’t work for groups?

    function bp_cover_group_img_path() {
    	// Is the current page a user page?
    	if ( bp_is_group() ) {
    
    	$group_id = bp_get_group_id();
    
    	$attachment = bp_attachments_get_attachment( 'url', array( 'item_id' => $group_id ) );
    
    	$image_path = $attachment;
    	// output only if an attachment exist
    	if( !empty( $attachment ) ):
    		echo $image_path;
    	endif;
    
    	}
    }
    add_action( 'bp_group_cover_path', 'bp_cover_group_img_path' );

    danbp
    Moderator

    @danbp

    You need to specify the object.

     $attachment = bp_attachments_get_attachment( 'url', array( 
       'object_dir' => 'groups',  
       'item_id' => $group_id,  
    ) );

    Reference

    bp_attachments_get_attachment


    m1000
    Participant

    @m1000

    Thanks again

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolve] How to retrieve a direct path to cover image in cover-image-header.php’ is closed to new replies.
Skip to toolbar