Detecting embeded video format

so you place your video inside a shortcode and then you can run a filter on that shortcode function. works like this (to be placed inside functions.php or some custom plugin): function so327822_wp_video_shortcode($output, $atts) { //get video ID by src $video_id = attachment_url_to_postid( $atts[‘src’] ); //get video meta $video_meta = wp_get_attachment_metadata( $video_id ); //uncomment next … Read more

menu item to display the most recent post

If you want to perform any redirects, you have to send your header before site sends any output. Shortcodes are run when the content is obtained, parsed and printed. So the site will already be partially sent to the browser, so you won’t be able to perform any redirects any more. So you should run … Read more

Show own shortcode data on each page

Best way to achieve the desired functionality is to use post_meta / custom field. add_shortcode (‘cities’, ‘show_cities’); function show_cities(){ /* Create a custom field ‘city’ to save city name in page editor */ $city = get_post_meta( get_the_id(), ‘city’, true ); return $city; } Using an array can also do the work as under: add_shortcode (‘cities’, … Read more

Using a shortcode to create a dropdown menu from wp_nav_menu list items

You can use wp_get_nav_menu_items() which retrieves all menu items of a navigation menu. Your shortcode callback should be something like this . function print_menu_shortcode($atts, $content = null) { extract( shortcode_atts( array( ‘name’ => null, ‘class’ => null ), $atts )); // Assuming $name contains slug or name of menue $menu_items = wp_get_nav_menu_items($name); // Sample Output. … Read more

add_shortcode is not working in plugin where others are working

Your shortcode callback function is incorrect: add_shortcode(‘load_peoplesoft_result_page’, ‘load_peoplesoft_results()’); You’ve included the (), but only the function name should be passed: add_shortcode( ‘load_peoplesoft_result_page’, ‘load_peoplesoft_results’ ); Note that the second argument of add_shortcode() is a “callable”. This is a standard PHP feature, and you can read documentation for them here.

How do you stop a shortcode from firing in the editor?

First follow what the codex says Shortcodes. Basically you just wrap your html in ob_start(); this will return the html as a string so you can echo it. 1st way : function my_shortcode() { ob_start(); ?> <HTML> <here> … <?php return ob_get_clean(); } 2nd way function my_shortcode() { $output=””; $output.= ‘<html>content</html>’; return $output; }

shortcode to display post by category entered by user without plugin

Try the below code. I think it could help you. add_shortcode( ‘knowledge_sharing’, ‘cat_post’ ); function cat_post($atts){ // attributes for shortcode if (isset($atts[‘cat’])) {$cats = $atts[‘cat’];} else {return;} if (isset($atts[‘posts_per_page’])) {$posts_per_page = $atts[‘posts_per_page’];} else {$posts_per_page = -1;} // get the category posts $category = get_category_by_slug($cat); if (!is_object($category)) {return;} $args = array( ‘cat’ => $category->term_id, ‘posts_per_page’ => … Read more