General Settings: display custom plugin field after Site Address field

Figured it out by using the following jQuery function. The #protocol_relative is the field I am inserting and #home-description is the field I am inserting it after: add_action( ‘admin_footer’, ‘insert_field’ ); function insert_field() { # Insert the settings field after the ‘Site Address (URL)’ ?> <script type=”text/javascript”> jQuery( ‘#protocol_relative’ ).closest( ‘tr’ ).insertAfter( jQuery( ‘#home-description’ ).closest( … Read more

Passing Jquery value to WordPress function

You have to use AJAX for that. What you have to do is: Create a JS script which sends an AJAX request to admin-ajax.php file: <script> jQuery(“.author-popup”).on(“click”, function(){ var id = jQuery(this).attr(“id”); jQuery.post(“http://www.yourdomain.com/admin-ajax.php”, {action: “my_author_box”, id: id}, function(response){ console.log(“Response: ” + response); //NOTE that ‘action’ MUST be the same as PHP function name you want … Read more

jQuery – Toggle megamenu submenu items by click

Try this -> jQuery(document).ready(function($) { $(‘#menu-main-menu a’).click(function( event ){ var visibleSubmenu = $(‘#menu-main-menu ul.sub-menu:visible’); var submenu = $(this).next(‘ul.sub-menu’); if( submenu.length >= 1 ) { event.preventDefault(); visibleSubmenu.slideUp(); submenu.slideToggle(); } }); });

jQuery selectable() function won’t work in wordpress

I always refer to to this blogpost about how to including jQuery code in WordPress. It shows you how to use noConflict within your javascript-code. var $j = jQuery.noConflict(); $j(function(){ // YOUR CODE HERE } } Also make sure that the jQuery library is included on the frontside of your WordPress installation with the wp_enqueue_script-function. … Read more

how to get permalink

To get a permalink you need to use get_permalink(). Just pass the ID of the post or leave it blank to get the current page in the Loop. wp_localize_script () will render PHP variables on the page that are consumable by JS through a global object that you define. PHP // Register the script wp_register_script( … Read more

How to Query in WordPress which shows Alphabetic Posts?

Assuming the letters are links, then put the letter into the URL as a parameter. E.g.: http://example.com/brands/?letter=N Then, in the code (inside whichever template file will be used here), you need to query the DB for posts/brands beginning with ‘N’. You can either create a taxonomy for letters (https://codex.wordpress.org/Function_Reference/register_taxonomy) and assign each post to a … Read more

jQuery script doesn’t work on WordPress

Initialize the Scroll to Top script from within another JavaScript file. I’m assuming that jquery.backtotoplink.js is coming from a third party and that it should not be modified. For example, in a theme, the JavaScript could be enqueued like this: function wpse247853_scripts() { // jquery.backtotoplink.js depends on jquery wp_enqueue_script( ‘scrolltotop’, get_template_directory_uri() . ‘/js/jquery.backtotoplink.js’, array( ‘jquery’ … Read more

How to load jQuery in TOP of wp_footer?

To properly enqueue jQuery, it’s usually done with wp_enqueue_scripts, there’s no need to load it from cdn as jQuery library are provides in the wp-includes folder of WordPress. Only wp_enqueue_script(‘jquery’); is required. add_action(‘wp_enqueue_scripts’, ‘replace_jquery’); If you really want to replace jQuery with the cdn link, it’s better to register and enqueue it with this function.