How do I enqueue a JavaScript in my footer via the functions.php file?

First, create a static js file with those inline codes.. !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0]; if(!d.getElementById(id)){js=d.createElement(s);js.id=id; js.src=”https://platform.twitter.com/widgets.js”; fjs.parentNode.insertBefore(js,fjs);} }(document,”script”,”twitter-wjs”); var options = { “url”: “/my-styles.css” }; CustomizeTwitterWidget(options); Then enqueue it at footer as the dependent of twitter-customize script which you already enqueued. function my_footer_enqueue() { wp_register_script( ‘twitter-customize’, get_template_directory_uri() . ‘/js/customize-twitter-1.1.min.js’, array(), ‘1.0’, true ); wp_enqueue_script( ‘twitter-customize’ ); wp_enqueue_script( … Read more

storing wp_head in a variable?

This function doesn’t take any params, so there is no nice way of doing it. But of course you can do this PHP way using output buffering 😉 ob_start(); wp_head(); $var = ob_get_clean();

Change location of header.php and footer.php

It is not possible to override header/footer via hooks in respective get_header()/get_header() functions. However it is often overlooked that these function allow input and loading different headers. For example get_header( ‘nested/header’ ); will look for header-nested/header.php in theme’s folder. It’s kind of a hack in regards to subdirectory use, but it works. 🙂

Is possible dequeue/remove style from wp_footer() hook and add on wp_head() hook?

If you look at the source code, you can see that wp_enqueue_style( ‘crayon’ ) is called in Crayon::enqueue_resources() which itself is called either from either Crayon::the_content() or Crayon::wp_head(). The code in Crayon::wp_head is: if (!CrayonGlobalSettings::val(CrayonSettings::EFFICIENT_ENQUEUE) || CrayonGlobalSettings::val(CrayonSettings::TAG_EDITOR_FRONT)) { CrayonLog::debug(‘head: force enqueue’); // Efficient enqueuing disabled, always load despite enqueuing or not in the_post self::enqueue_resources(); } … Read more

Only loads on the contact template page

First a bit of advise (since the solution is based on it) – always “enqueue” your scripts, don’t just add them in the footer. Read this, for example . Now the solution for loading scripts on specific template, since this is what you asked for: function enqueue_themescrits() { if ( is_page_template(‘contact.php’) ) { //the file … Read more

How can I selectively print scripts to the footer of certain admin pages?

There’s an in_footer parameter that you can pass to wp_enqueue_scripts – does that work? I would hook to admin_enqueue_scripts, check the $page for location, and enqueue your script there, with ‘in_footer’ as true. Example: add_action( ‘admin_enqueue_scripts’, ‘enqueue_my_script’ ); function enqueue_my_script( $page ) { if ($page !== ‘edit.php’) return; wp_enqueue_script( ‘my-script’, ‘http://path/to/my/local/script’, null, null, true ); … Read more

How can I customize wp_footer, where is the code that controls what this function does?

This could be multiple things. I’m not sure what the credits do. However, the chance is quite big that the search field is being created by a widget, shown in the get_sidebar(‘main’). Under “Appearance” > “Widgets”, you should be able to find more information. The template being called is probably sidebar-main.php. If it is a … Read more

Add external js file to footer with id

You can use the script_loader_tag hook function enqueue_validation_script() { wp_register_script( ‘validation’, ‘https://www.asd.in/script.php?id=3ff00a469474bbe71a9218a7f0377518’, array( ‘jquery’ ) ); wp_enqueue_script( ‘validation’ ); } add_action(‘wp_enqueue_scripts’, ‘enqueue_validation_script’); function add_id_to_validation_script( $tag, $handle, $src ) { if ( ‘validation’ === $handle ) { $tag = ‘<script type=”text/javascript” id=”3ff00a469474bbe71a9218a7f0377518″ src=”‘.$src.'”></script>’; } return $tag; } add_filter( ‘script_loader_tag’, ‘add_id_to_validation_script’, 10, 3 );

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)