Tagged: x
-
AuthorPosts
-
February 9, 2017 at 9:50 am #1364413
Christian SParticipantHello,
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 AssenmacherFebruary 9, 2017 at 11:53 am #1364592
RupokMemberHi 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.
February 10, 2017 at 6:50 am #1365781
Christian SParticipantI 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.
February 10, 2017 at 10:22 am #1366013
Nabeel AModeratorHi 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!
March 2, 2017 at 8:19 am #1391842
Christian SParticipantThank you!
March 2, 2017 at 9:08 am #1391941
RahulModeratorYou’re most welcome!
Feel free to ask us again if you’ve any further queries regarding the X-theme.
Thanks!
March 3, 2017 at 4:03 am #1393114
Christian SParticipantHmm 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' );March 3, 2017 at 5:18 am #1393148
Christian SParticipantok nvm works fine 🙂
March 3, 2017 at 5:36 am #1393170
FriechModeratorWe’re delighted to assist you with this.
Cheers!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1364413 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
