Display content from another site page using a shortcode

You can create a shortcode as below: function wpse250662_post_content_shortcode($atts) { $args = shortcode_atts( array( ‘pagename’ => ” ), $atts ); $query = new WP_Query( $args ); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); $content = apply_filters(‘the_content’,get_the_content( )); ob_start(); ?> <div class=”content”> <?php echo $content; ?> </div> <?php endwhile; endif; wp_reset_postdata(); return … Read more

How do you pass parameters TO a shortcode?

Let’s say you have a form that sends the data in the following way: <form method=”post” name=”car-select” action=”<?php echo site_url(‘/my-page/’); ?>”> <select name=”make”> <option value=”benz”>Benz</option> <option value=”bmw”>BMW</option> <option value=”audi”>Audi</option> </select> <input type=”submit” value=”Find my dream car!”/> </form> Now you want to query some posts based on users choice right? This is where $_POST comes in … Read more

Adding json as params to shortcode

You could create a shortcode with only one attribute and that attribute could be the ID of a custom post type or the name of a site option: [example id=”123″] Multiple instances of the framework If you need to have multiple instances of that js framework with different attributes, then you could create a custom … Read more

get_page_by_title with an apostrophe in variable

Title Hello world!@#$%^*(),.;:\ will work but any title you enter containing ‘ ” < > & characters won’t work because in $content variable you have escaped HTML entities so Mal’s Post becomes Mal&#8217;s Post. To bypass it you can use sanitize_title function along with get_page_by_path. function shortcode_equipment($atts, $content = null) { $path = sanitize_title($content); $equipment … Read more

How would I create a shortcode to display a custom post within a page or regular post?

There are great tutorials about shortcodes all over the web and some good examples here but just to get you started: add_shortcode(‘film_q’, ‘film_shortcode_query’); function film_shortcode_query($atts, $content){ extract(shortcode_atts(array( // a few default values ‘posts_per_page’ => ‘1’, ‘post_type’ => ‘film’, ‘caller_get_posts’ => 1) , $atts)); global $post; $posts = new WP_Query($atts); $output=””; if ($posts->have_posts()) while ($posts->have_posts()): $posts->the_post(); … Read more

How can i remove the paragraph from shortcodes content?

The shortcodes, since they are inserted in the editor, comply to editor rules. Hitting the return in editor will generate a paragraph tag, just like any other text. It’s one of the TinyMCE features. To read more about TinyMCE check out their forum and especially this thread

How Can I Pass the Shortcode’s $atts Variable to the Plugin’s Javascript Function

You need to have some initial (maybe global) js var markers_array = [];. Then use an ajax callback function to bump your markers into that array. Register your scripts // Define $root_url = plugin_dir_path(); // Example path $ajax_nonce=”your_nonce”; $ajax_nonce_val=”your_val”; // Ajax wp_register_script( ‘json2’, false, false, false, true ); wp_enqueue_script( ‘json2’ ); wp_enqueue_script( ‘ajax-script’ ,”{$root_url}js/ajax_json.js” // … Read more

Using do_shortcode with variables?

Your syntax is broken, the quote marks do not match. Try to separate data from the shortcode template, and use sprintf(): $shortcode = sprintf( ‘[pw_map address=”%1$s %2$s %3$s %4$s” width=”%5$s” height=”200px”]’, $address, $city, $province, $postalcode, ‘100%’ ); echo do_shortcode( $shortcode ); That’s much easier to read, and it is harder to create syntax errors. 🙂

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)