Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Problem using bp_is_profile_edit() to enqueue script from functions.php


  • enderpal444
    Participant

    @enderpal444

    Im trying to only enqueue a script on the profile edit page. I figured I could just do it like this but it doesn’t work. I tested it without the condition to make sure it was linked correctly and it was. Any idea why it doesn’t work?

    `if ( bp_is_profile_edit() ) {
    wp_enqueue_script( ‘limit_char’, get_bloginfo(‘stylesheet_directory’).’/libs/limit-char.js’ );
    }`

Viewing 6 replies - 1 through 6 (of 6 total)
  • Try this:
    `if( bp_is_profile_component() && ‘edit’ == bp_current_action() )`

    To get that running from functions.php I had to add it to bp_init so you’ll need to play around with things.


    enderpal444
    Participant

    @enderpal444

    @hnla Thanks for helping. What do I add to bp_init? I tried that in the functions.php but it didn’t do the trick/

    That was more by way of saying that I needed to pass this through a hook of some description and used bp_init for the sake of it. I would have hoped that simply adding your function to wp_enqueue_scripts would have worked but think there may be issues with page already having been parsed in order to determine those page conditions.

    this ought to work:

    `
    function enqueue_limit_char() {
    if ( !is_admin() ) {
    if( bp_is_profile_component() && ‘edit’ == bp_current_action() )
    wp_enqueue_script();
    }
    }
    add_action(‘wp_enqueue_scripts’, ‘enqueue_limit_char’);
    `


    enderpal444
    Participant

    @enderpal444

    @hnla yeap sure did. I can’t really tell what is so different that is happening but it works lol!

    All working then? we can mark thread as resolved if so.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] Problem using bp_is_profile_edit() to enqueue script from functions.php’ is closed to new replies.
Skip to toolbar