How to check if a shortcode exists?
#23572 introduced shortcode_exists() into 3.6.
#23572 introduced shortcode_exists() into 3.6.
try : if (strpos($post->post_content,'[gallery’) === false){ $gallery = 0; }else{ $gallery = 1; }
Say you have image foo.jpg and bar.jpg in your media library. foo.jpg has caption saying “foo”, and bar.jpg has caption saying “bar”. Create a gallery with those two images, they will show with “foo” and “bar” captions. Want to use them again with a different caption, but using a gallery? No problem. Make another gallery … Read more
First add your additional buttons inside the buttons callback.. function register_button($buttons) { array_push($buttons, “quote”,”wpse-rules”); return $buttons; } Then add additional buttons function inside the plugin javascript.. init : function(ed, url) { ed.addButton(‘quote’, { title : ‘Add a Quote’, image : url+’/image.png’, onclick : function() { ed.selection.setContent(‘[quote]’ + ed.selection.getContent() + ‘[/quote]’); } }); ed.addButton(‘wpse-rules’, { title … Read more
I am not a jQuery expert, but I ran into the same problem and I believe I have a workable solution. The problem is that each time you run wp_localize_script it creates a javascript variable using the $name setting. In your case that is ‘carouselvars’. As this is set before the jQuery in run, only … Read more
This is pretty much what Foxsk8 mentioned in a comment, so credit should go to him, but these additional instructions will be useful. The WordPress plugin called TinyMCE Advanced will solve your problem. This plugin comes with an option inside Settings > TinyMCE Advanced that will fix your disappearing <p> tags. Mark the checkbox labeled … Read more
If I understand your question correctly, you want to be able to get the parameter from the url, add it to the shortcode so you can add the parameter to the content. See if this works: add_shortcode(‘name’, ‘get_name’); function get_name() { return $_GET[‘name’]; } In the wordpress backend editor you would have something like: Hello … Read more
If you take a look at the Codex page about add_shortcode() you won’t see anything about the need of an add_action() before you can use add_shortcode(). So, you can just put your add_shortcode() directly into your functions.php. This is what I do too. See this article – WordPress Shortcodes: A Complete Guide about the use … Read more
First off, it’s always good to register shortcode during init versus just in your general functions.php file. At the very least add_shortcode() should be in init. Anyway, let’s begin! Whenever you use add_shortcode() the first parameter is going to be the name of the shortcode and the 2nd will be the callback function. This means … Read more
add_shortcode( ‘related-article’, ‘related_article_title’ ); function related_article_title( $atts ) { global $post; echo $post->ID; // currently viewing post id ob_start(); $query = new WP_Query( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 1, ‘order’ => ‘DESC’, ) ); if ( $query->have_posts() ) { ?> <div class=”menu-row”> <?php while ( $query->have_posts() ) : $query->the_post(); ?> Leggi anche: <a href=”https://wordpress.stackexchange.com/questions/210518/<?php … Read more