Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1364413
    Christian S
    Participant

    Hello,

    i want to add 5 .js and 2 css files to my homepage, made by wordpress (they are creating a button which allows visitors to make a call).
    I uploaded the .js to my ftp and linked them on the site i want them to be placed in.
    “<script type=’text/javascript’ src=’mylink’></script>” …
    I created a function in functions.php to add the code on the site:

    function fuege_javascripts_ein()
    { $url_h = get_template_directory_uri().’/verzeichnis/js-datei-fuer-header.js’;
    wp_enqueue_script( ‘handler_name_eins’, $url_h, false, null, false );}
    add_action( ‘wp_enqueue_scripts’, ‘fuege_javascripts_ein’ );

    Why are they not working? My problem is that i know nothing about wordpress, i just made the scripts and tested them localy (successfull) but on the homepage (made by a co-worker with wordpress who doesnt know anything about programming) they are not working. What could cause this issue?
    The script is adding html code to a id-desired div-container on the website.

    Greetings,
    Christian Assenmacher

    #1364592
    Rupok
    Member

    Hi there,

    If you want to add them for home page only, you can enqueue them within functions.php like this :

    function mytheme_enqueue_front_page_scripts() {
        if( is_front_page() )
        {
            wp_enqueue_script( 'homecustom-css', get_template_directory_uri().'/verzeichnis/js-datei-fuer-header.CSS' ), null, true );
            wp_enqueue_script( 'homecustom-js', get_template_directory_uri().'/verzeichnis/js-datei-fuer-header.js' ), null, true );
        }
    }
    add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_front_page_scripts' );

    Hope this helps.

    #1365781
    Christian S
    Participant

    I added the code to functions.php. Now i cant access the website giving “HTTP ERROR 500”. After deleting your code in functions.php, the page is working again. I copied wp_enqueue_script() for each file and replaced ‘homecustom-css’ and ‘homecustom-js’ with unique names.

    #1366013
    Nabeel A
    Moderator

    Hi again,

    Please replace the previous code with the following code:

    function enqueue_styles() {
    	if( is_front_page() ) {
    		wp_enqueue_style( 'js-datei-fuer-header', get_template_directory_uri().'/verzeichnis/js-datei-fuer-header.CSS', false ); 
    	}
    }
    
    function enqueue_scripts() {
    	if( is_front_page() ) {
    		wp_enqueue_script( 'js-datei-fuer-header', get_template_directory_uri().'/verzeichnis/js-datei-fuer-header.js', false );
    	}
    }
    
    add_action( 'wp_enqueue_scripts', 'enqueue_styles' );
    add_action( 'wp_enqueue_scripts', 'enqueue_scripts' );

    Change the file names and path of the files accordingly.

    Let us know how this goes!

    #1391842
    Christian S
    Participant

    Thank you!

    #1391941
    Rahul
    Moderator

    You’re most welcome!

    Feel free to ask us again if you’ve any further queries regarding the X-theme.

    Thanks!

    #1393114
    Christian S
    Participant

    Hmm the scripts are added to the sourcecode of the page but they just do nothing. I already added a nonsense part to the script that would cause an error, but it seems they just were ignored (no error shown when i load the page). Also no console outputs etc.
    Am i not finished yet? What do i have to do to make them work?

    Thats the part i added to functions.php:

    
    function enqueue_styles() {
    	if(is_page(477))
    	{
    		wp_enqueue_style( 'innovaphone.widget.BusinessCard', '/wp-content/themes/x/Buttons/innovaphone.widget.BusinessCards.css', false ); 
    		wp_enqueue_style( 'innovaphone.widget.general', '/wp-content/themes/x/Buttons/innovaphone.widget.general.css', false ); 
    	}
    	
    }
    
    function enqueue_scripts() {
    	if(is_page(477))
    	{
    		wp_enqueue_script( 'innovaphone.common.cypto', '/wp-content/themes/x/Buttons/innovaphone.common.crypto.js', false );
    		wp_enqueue_script( 'innovaphone.pbxwebsocket.Connection', '/wp-content/themes/x/Buttons/innovaphone.pbxwebsocket.Connection.js', false );
    		wp_enqueue_script( 'innovaphone.pbxwebsocket.ToneGenerator', '/wp-content/themes/x/Buttons/innovaphone.pbxwebsocket.ToneGenerator.js', false );
    		wp_enqueue_script( 'pbxwebsocket.WebRtcEndpoint', '/wp-content/themes/x/Buttons/innovaphone.pbxwebsocket.WebRtcEndpoint.js', false );
    		wp_enqueue_script( 'CallMeButtons', '/wp-content/themes/x/Buttons/innovaphone.widget.CallMeButtons.js', false );
    	}
    	
    }
    
    add_action( 'wp_enqueue_scripts', 'enqueue_styles' );
    add_action( 'wp_enqueue_scripts', 'enqueue_scripts' );
    #1393148
    Christian S
    Participant

    ok nvm works fine 🙂

    #1393170
    Friech
    Moderator

    We’re delighted to assist you with this.

    Cheers!

  • <script> jQuery(function($){ $("#no-reply-1364413 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>