How can I make a shortcode from this code?

It should be as simple as this: function item_count() { $dir=”/PATH TO DIRECTORY/”; $filecount = 0; $d = dir( $dir ); while ( $f = $d->read() ) { if ( ( $f!= “.” ) && ( $f!= “..” ) ) { if( ! is_dir( $f ) ) { $filecount++; } } } return ‘(‘ . … Read more

WordPress menu deletes when trying to add a hook

I don’t think there’s wp_nav_menu action. Perhaps you want the wp_nav_menu filter (doc)? function custom_novice_menu($args) { if( ‘primary’ == $args[‘theme_location’] ) // only apply to the right menu { $args[‘container’] = ‘div’; } return $args; } add_filter(‘wp_nav_menu’, ‘custom_novice_menu’);

Can’t get JS code to work with shortcode

You need to return the Shortcode generated string, not echo, like this: function gg_product_front_end() { wp_register_script( ‘gg_loadProducts_frontEnd’, plugins_url( ‘js/front_end.js’, __FILE__ ), array( ‘jquery’ )); wp_enqueue_script( ‘gg_loadProducts_frontEnd’ ); return ‘<p id=”test”>Test!</p>’; } Also, you need to call the JavaScript function, like this: function gg_loadProducts_frontEnd() { console.log( ‘Test!’ ); } gg_loadProducts_frontEnd(); Otherwise Test! will not be logged … Read more

shortcode to output multiple images urls from media library id

Try this function image_thingy($atts) { // Merge attribtes from shortcode with defaults extract(shortcode_atts(array( ‘id’ => 1, ), $atts)); // Extract id’s from shortcode attributes and convert into an array $ids = explode(‘,’,$atts[‘id’]); $output=””; // Variable that holds the shortcode output, at the end this will be returned // Loop through ids and fetch urls, and … Read more