Skip to:
Content
Pages
Categories
Search
Top
Bottom

apply js file only to the bbp forum


  • haddlyapis
    Participant

    @haddlyapis

    I have been trying to assign some js files only to their respective pages on my site, instead of loading them everywhere and have been successful apart from with my forum area.
    in my functions.php file i have tried the following:

    
    add_action ('wp_print_scripts', 'deregister_forum_scripts');
    
    function deregister_forum_scripts(){
         if ( !is_page('forum') (is_page() && in_array( 19306, get_post_ancestors( get_the_ID() ) ) ) ) {
         wp_deregister_script('forum-js');
    
    }}
    

    whereby i got the id 19306 from my database by doing:
    select ID from wp_posts where post_name = 'forum';
    As the page is http://www.apis.de/forum/
    The issue is, even if I leave out the second part of the “if” statement (i.e. “is_page()….), it doesn’t work.
    I assume this is because my forum is implemented differently to the rest of my site and is not a normal “is_page(….)”.
    Can anyone advise here how to target the forum via PHP?
    Also, i don’t think i should be using “get_post_ancestors” but “get_page_children“. But that is another topic.

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

  • Robin W
    Moderator

    @robin-w

    is_bbpress()


    haddlyapis
    Participant

    @haddlyapis

    Perfect. Thx Robin!!
    The following now works

    /* only run forum script in forum area */
    add_action( 'wp_print_scripts' , 'deregister_forum_script');
    
    function deregister_forum_script(){
    if ( !is_bbpress() ){
        wp_deregister_script('forum-js');
    }}

    This ticket is now closed. thx!


    Robin W
    Moderator

    @robin-w

    great – glad you are fixed !

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