Get post meta in enqueued js file

You can send variables to your script with wp_localize_script: wp_enqueue_script( ‘some_handle’ ); global $post; $my_meta = get_post_meta( $post->ID, ‘my_meta’, true ); $array = array( ‘my_meta’ => $my_meta ); wp_localize_script( ‘some_handle’, ‘object_name’, $array ); You can then use the var in your script like: object_name.my_meta

Javascript included but alert() function not working

A few things: The version of jQuery that ships with WordPress is run in noConflict() mode. Meaning you have to use jQuery instead of $ when you make your first reference. Don’t register your own version of jQuery when you’re developing. You’re locking yourself in to a single version that may or may not be … Read more

Ajax template: how to handle head section

Ok, you want that mobile devices always load mobile templates. Desktop devices load template files based on resolution: if < 1080 mobile ones, > 1080 desktop ones. Your workflow should be: On init you check for mobile devices using wp_is_mobile. If true you add a template filter that returns str_replace(‘.php’, ‘-mobile.php’, $template); where $template is … Read more

Adding a class (arrows) to main menu links that have children?

There are two ways of doing this: Javascript. You could use JQuery to select the <li> that have <ul> children of class ‘sub-menu’, inserting content, or appending a CSS class which you then style. For example: $(‘.sub-menu’).parent().addClass(‘myclass’) PHP, a new walker function. Copy the code from wp-includes/nav-menu-template.php (until approx line 109) into your themes functions.php … Read more