Escaping quotes from shortcode attributes
It seems you are working on the wrong end. Try sanitizing the user input, for instance by means of sanitize_text_field, not the shortcode output.
It seems you are working on the wrong end. Try sanitizing the user input, for instance by means of sanitize_text_field, not the shortcode output.
Shortcode functions are only called when the content of the visual editor is processed and displayed, so nothing in your shortcode function will run early enough. Have a look at the has_shortcode function. If you hook in early enough to send headers and late enough for the query to be set up you can check … Read more
Try this function get_products($atts) { ob_start(); get_template_part(‘block-products-inline’); return ob_get_clean(); } add_shortcode(‘products’, ‘get_products’); Little explanation php just outputs your content right away when its see print statement. What we do here is, we are holding all the output in buffer and not giving it in print until the whole things finish. then we are returning the … Read more
The problem with what you’re trying to do is that you split a block type html element <p>. In your example you effectively have <p><div></p></div>, which is simply no good. So you cannot mix <p> and <div> in this way. You can, however use a combination of paragraphs and classes: <p>Text</p><p class=”hide-from-here”>More text</p> Where it … Read more
No, there is no core shortcode for this. The site name is available as an option, in facts get_option(‘blogname’) returns the blog name. Moreover, get_bloginfo(‘name’) / bloginfo(‘name’) can be used to get / echo the site name. Of course, you can’t use that functions as a shortcode by default, so if you want to obtain … Read more
If you want exactly this shortcode: to output nothing, then you can use the wp_video_shortcode_override filter or the wp_video_shortcode filter to achieve that. Here are two such examples: Example #1 /** * Let the shortcode output “almost” nothing (just a single space) for specific attributes */ add_filter( ‘wp_video_shortcode_override’, function ( $output, $attr, $content, $instance ) … Read more
The easiest way to do that is to hijack the gallery shortcode (no extra regex needed), store it somewhere and add it to the end. Prototype <?php # -*- coding: utf-8 -*- /** * Plugin Name: T5 Move Galleries To End Of Content */ add_action( ‘after_setup_theme’, array ( ‘T5_Move_Galleries’, ‘init’ ) ); class T5_Move_Galleries { … Read more
to read the attribut country, you just need to read it in $atts add_shortcode( ‘ifurl’, ‘ifurl’ ); function ifurl($atts, $content = null) { $url=”https://” . $_SERVER[‘SERVER_NAME’]; $current_tld = end(explode(“.”, parse_url($url, PHP_URL_HOST))); if ($current_tld === $atts[“country”]) { return $content; } };
this is very simple to do… // next function next_shortcode($atts) { // global $post; -unnecessary return ‘<div class=”nav-next”>’.next_post_link( ‘%link’, ‘%title <span class=”meta-nav”>’ . _x( ”, ‘Next post link’, ‘ ‘ ) . ‘</span>’,true ).'</div>’; } add_shortcode( ‘next’, ‘next_shortcode’ ); //prev function prev_shortcode($atts) { //global $post; -unnecessary return ‘<div class=”nav-previous”>’.next_post_link( ‘%link’, ‘%title <span class=”meta-nav”>’ . _x( … Read more
You have to either 1) take all the whitespace out of the script so WordPress does not add <p> tags and then the JS will work, or 2) disable autop in the post editor for all posts/pages (see http://codex.wordpress.org/Function_Reference/wpautop ) so WP doesn’t add paragraph breaks, or 3) do the following, which leaves autop enabled … Read more