Pass Shortcode Attribute to footer Script

It’s simple. WordPress have a handy function to send variables to a registered script. It’s wp_localize_script. It work this way: //First Register Your Script wp_register_script( ‘name-of-script’, ‘http://example.com/script.js’, ”, ”, true ); //Then send dynamic variables wp_localize_script( ‘name-of-script’, ‘globalVar’, array( ‘id’ => ‘slideTarget’ ) ); //Finally invoke it on Front-End wp_enqueue_script ( ‘name-of-script’ ); This should … Read more

Need to turn this php into WP shortcode

Init your shortcode add_shortcode(‘shortcode_ald_crp’, ‘myshortcode_echo_ald_crp’); The function what you want: function myshortcode_echo_ald_crp() { ob_start(); if ( function_exists( ‘echo_ald_crp’ ) ) echo_ald_crp(); return ob_get_clean(); } you call you shortcode in a post like this: [shortcode_ald_crp] Or into the php code: echo do_shortcode(‘[shortcode_ald_crp]’); UPDATE Change the function add_shortcode shortcode_ald_crp for myshortcode_echo_ald_crp

How to change the page break numbering?

Put this function in you functions.php – function the_dramatist_wp_link_pages( $args=”” ) { global $page, $numpages, $multipage, $more; $defaults = array( ‘before’ => ‘<p>’ . __( ‘Pages:’ ), ‘after’ => ‘</p>’, ‘link_before’ => ”, ‘link_after’ => ”, ‘next_or_number’ => ‘number’, ‘separator’ => ‘ ‘, ‘nextpagelink’ => __( ‘Next page’ ), ‘previouspagelink’ => __( ‘Previous page’ ), … Read more

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