On a custom template, should I use wp_footer? [duplicate]

<?php function theme_footerscript(){ wp_enqueue_script(‘main_js’, get_template_directory_uri() . ‘/assets/js/main.js’, array(‘jquery’), ‘1.0’, true); } add_action(‘wp_enqueue_scripts’, ‘theme_footerscript’); ?> this way you will add a script on footer (add this code in functions.php). if you set the last parameter to true, then the script will be at the bottom of html page. you can check on WordPress Codex

Escape html structure in php

The answer typically depends on where your translations come from. WordPress core doesn’t usually escape strings such as this, but you may wish to do so in your plugin. A translation might come from an “untrusted” source and could, in theory, contain malicious JavaScript, and escaping would protect you from this. In reality that’s unlikely, … Read more

Add end mark at the end of every article

The end of the_content() is a </p> tag. It sounds like you want to include your end mark before that last </p> tag. If so, you need a function that filters the_content(). Something like: function yang_end_mark( $content ) { $content = substr_replace($content, ‘<span>&#128282;</span></p>’, strrpos($content, ‘</p>’), strlen(‘</p>’)); return $content; } add_filter( ‘the_content’, ‘yang_end_mark’, 25 ) ;

How to call javascript function (jquery) in a shortcode?

Use wp_enqueue_script() with $in_footer parameter set to true, when loading scripts with your shortcode. To pass data from the PHP part of your code to the JS part use wp_localize_script(). wp_enqueue_script( ‘script_name’, ‘/script-location/script.js’, array(), ‘1.0.0’, true ); $data_array = array( ‘key_1’ => ‘val_1’, ‘key_2’ => ‘val_2’ ); wp_localize_script( ‘script_name’, ‘data_object_name’, $data_array ); You now can … Read more

Facebook like update status for wordpress

The Buddypress plugin allows your users to have a profile and create status posts (Facebook style updates) . It’s a very popular and free plugin to use. It appears when going to the Add Plugins page in the Admin area. To add more functionality they’re lots of plugins that play well with Buddypress but not … Read more

Even with PHP plugin get_posts not working in widget area

Tuns out it needed: global $post Complete working code: <div class=”aboutgridcont”> <ul class=”about-us-grid”> <li> <?php global $post; $posts = get_posts(‘post_type=employee&orderby=rand&numberposts=16′); foreach($posts as $post) { ?> <img class=”headshot” src=”https://wordpress.stackexchange.com/questions/196622/<?php the_field(“headshot’); ?>”> <?php } ?> </ul> </div>

Custom post type single page return to listing page

Ok i got answer by my own I just put the single file condition above the file template Here is my code: add_filter(‘template_include’, ‘foo_template_chooser’); function foo_template_chooser($template){ global $wp; $plugindir = dirname(__FILE__); if( $wp->query_vars[“post_type”] == ‘my_items’ && is_single() ){ if(file_exists(TEMPLATEPATH . ‘/my_items/single-my_items.php’)) { return locate_template(‘my_items/single-my_items.php’); } else { return $plugindir . ‘/template/single-my_items.php’; } } if( $wp->query_vars[“post_type”] … Read more