{"id":3703,"date":"2021-10-28T11:56:56","date_gmt":"2021-10-28T09:56:56","guid":{"rendered":"https:\/\/www.knowboard.de\/?p=3703"},"modified":"2022-09-27T13:42:08","modified_gmt":"2022-09-27T11:42:08","slug":"quickly-and-dirty-add-a-jquery-script-to-the-wordpress-footer","status":"publish","type":"post","link":"https:\/\/www.knowboard.de\/quickly-and-dirty-add-a-jquery-script-to-the-wordpress-footer\/","title":{"rendered":"Quickly and dirty add a JQuery script to the WordPress footer"},"content":{"rendered":"\n
I often search for such a script so now I got this ready made and perfectly at hand if I need it in the future. If you like you can use it too, I jzst need to write some text here so that this post does not look too empty. Thanks.<\/p>\n\n\n\n
add_filter( 'wpex_get_social_items', function ( $items ) {\n\t$items['print'] = array(\n\t\t'site' => 'Print',\n\t\t'label' => 'Print',\n\t\t'li_class' => 'custom-print',\n\t\t'icon_class' => 'ticon ticon-print',\n\t\t'href' => '#print',\n\t);\n\treturn $items;\n} );\n\nadd_action( 'wp_enqueue_scripts', function() {\n\n\t$script = '\n\tjQuery( document ).ready(function() {\n\t\tjQuery( \".wpex-social-share li.custom-print a\" ).click( function() {\n\t\t\twindow.print();\n\t\t} );\n\t} );';\n\n\twp_add_inline_script( 'jquery', $script );\n\n} );<\/code><\/pre>\n\n\n\nAnother example:<\/h2>\n\n\n\n\/\/TOGGLE CART AFTER ADD TO CART CLICK\nadd_action( 'wp_footer', 'trigger_for_ajax_add_to_cart' );\nfunction trigger_for_ajax_add_to_cart() {\n \/*\n\tif ( isset($_POST['add-to-cart']) && $_POST['add-to-cart'] > 0\n && isset($_POST['quantity']) && $_POST['quantity'] > 0 ) :\n ?>\n <script type=\"text\/javascript\">\n (function($){\n $( \".topbar-cart-link\" ).trigger( \"click\" );\n\t\t\t\/\/ setTimeout(function(){ $( \".open-side-cart\" ).trigger( \"click\" ); }, 500);\n \/\/ Display an alert for testing purpose (To be removed)\n alert('\".open-side-cart\" Click!');\n\n })(jQuery);\n <\/script>\n <?php\n endif;\n\t*\/\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"I often search for such a script so now I got this ready made and perfectly at hand if I need it in the future. If you like you can use it too, I jzst need to write some text here so that this post does not look too empty. Thanks. Another example:<\/p>\n","protected":false},"author":1,"featured_media":3743,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-3703","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-allgemein","entry","has-media"],"_links":{"self":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts\/3703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/comments?post=3703"}],"version-history":[{"count":3,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts\/3703\/revisions"}],"predecessor-version":[{"id":3817,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts\/3703\/revisions\/3817"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/media\/3743"}],"wp:attachment":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/media?parent=3703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/categories?post=3703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/tags?post=3703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}