New answers tagged

0

Had similar problem ($post was null inside the rendering function). Sorted with the solution below: function bg_post_categories_shortcode( $atts, $content = null ) { global $post; $categories = get_the_category_list( ', ', '', $post->ID); return '<div class="gi__categories">' . $categories . '</div>'; } ...


-2

I would recommend using a shortcode, because its easy to use and at the same time efficient. Below I have attached the code, how you can put your code into a shortcode. the add_shortcode function is what you use when you want to create a shortcode. To use it, you simply need to write [render_slider_shortcode] anywhere you want your slider to be displayed. ...


0

This is the solution: function wpex_fix_shortcodes($content) { return strtr($content, [ '<p>[' => '[', ']</p>' => ']', ']<br />' => ']' ]); } remove_filter('the_content', 'wpautop'); remove_filter('the_content', 'do_shortcode', 11); add_filter('the_content', 'wpautop', 100); ...


0

Maybe try removing all the newlines from the output itself, since this is what is ultimately being messed with... $output .= '<div ' . implode(' ', $html_attributes) . '>'; $output .= '<a href="' . get_permalink() . '">'; $output .= '<div ' . implode(' ', $html_attributes_inner) . '>'; $output .= $logo; ...and so forth. If the newlines ...


0

After quite a bit of trial and error, I got the code set up correctly for the WordPress loop. I put it into a shortcode. Here it is: add_shortcode( 'partnerlogos', 'display_partner_logos' ); function display_partner_logos(){ // Define the query $args = array( 'post_type' => 'dnf_partner_logos', 'post_status' => 'publish' ); ...


0

Shortcodes are not parsed in widget text - you need to tell WordPress to do so: add_filter( 'widget_text', 'do_shortcode' ); Place it in your theme's functions.php


0

If you're entering this directly in the post editor, rather than have the Shortcode return the title, make a Shortcode to return the link with title. function adoption_link_function(){ global $post; $link = "parent.location='http://example.com/adoption-application/?Name={$post->post_title}'"; return '<input type="button" class="next-step" ...


0

You are using inline JavaScript, so it'll be fine to render shortcode like this; <input type="button" class="next-step" value="Adopt Now" onClick="parent.location='http://example.com/adoption-application/?Name=<?php echo do_shortcode('[Title]'); ?>'" />


1

You can not use a shortcode inside an attribute. You need to make a shortcode that will output the whole element.


1

Or little bit simplier. function do_shortcode_only_for($content, $tagnames) { $pattern = get_shortcode_regex($tagnames); $content = preg_replace_callback("/$pattern/", 'do_shortcode_tag', $content); return $content; } Taken from original do_shortcode function.


0

I've found a wordaround that "solves" the problem, but I'm not going to accept this as an answer until I'm not sure it is the only solution (which I suspect it is not). I can tell WP is not including the Ultimate VC Addons (UVCA from now on) CSS because my page does not contain any UVCA shortcode, or, at least, the initial page content doesn't. Shortcodes ...


0

Try this: function shortcode_func( $atts ) { ob_start(); echo 'shortcode output'; $output = ob_get_contents(); ob_end_clean(); echo $output; // Here comes the total output of your shortcode } add_shortcode( 'shortcode', 'shortcode_func' );


0

Using your comments, I found what I was missing. I initialized my textdomain with : add_action('admin_init', 'related_post_shortcode_init'); function related_post_shortcode_init() { load_plugin_textdomain('related-post-shortcode', false, basename( dirname( __FILE__ ) ) . '/i18n' ); } So, the textdomain was ok and ready for back-office translations ...


1

You need to recurse into the shortcode content ($m[5] as returned by get_shortcode_regex()), the standard way being to use preg_replace_callback(): public function wrapShortcode( $content ) { $content = preg_replace_callback( '/' . get_shortcode_regex() . '/s', array( $this, 'wrapShortcodeCallback' ), $content ); remove_filter( ...


3

I would prefer two array of images, captions. For example: I have added comments on the code for better understanding. function wpse216239_slider_shortcode( $atts , $content = null ) { // Attributes $atts = shortcode_atts( array( 'slides' => '', // one master attribute for slides 'captions' => '' // one ...


2

I think it's safe to say that wpautop() is a basket case without hurting anyone's feelings, but I wouldn't remove & add it at a different priority as that just makes things worse, as demonstrated (although what you posted is the browser trying to make sense of broken html, rather than the actual output, which does only have the <a> tag once). To ...


5

You are returning inside your loop - so it returns on the first iteration, giving you one result only. You should build a string inside your loop instead, and only return when the loop is over. Something like $featured_properties = ''; if( $featured_query->have_posts() ): while( $featured_query->have_posts() ) : ...


2

@setterGetter is right, you need to wrap it with do_shortcode() but you need to do it where the customizer field is called not inside the field within the customizer. In your case try looking in footer.php then if you're able to find where they output the code wrap it with echo do_shortcode() But that doesn't mean your shortcode will display properly, you ...


0

$gallery = shortcode_atts( array( 'post_gallery' => 'post_gallery', ), $atts ); $image_ids=explode(',',$gallery['post_gallery']); $sigle_img = wp_get_attachment_image_src($image_ids[0], "large"); $img="<div id='tourGallery'><img class='imgthumb' id='' ...


3

FINAL EDIT From comments Unfortunately when I try method one, all links go back to the homepage As I stated, everything works on my test install. I actually forgot that your code works for you, because you have hardcoded the URL <a href='/?$tax=$slug' ><h5> $term->name </h5></a> What this tells me is that get_term_link() ...


3

This could be done in the template that displays your archive page when only one post is returned by wp_query for a given category. Something like this: if ( $wp_query->post_count == 1 && $wp_query->max_num_pages == 1 ) { wp_redirect( get_permalink( $wp_query->posts['0']->ID ) ); exit; }


0

@Milo and @Howdy_McGee had the answer. I found the section I needed to modify in my functions.php file: case 'text': echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />', It was the value field that was getting truncated, so I passed it through ...


1

At first - do not use extract. It's very bad code style and is also depracated in core. Every time your foreach loop run, you override content of $output because you assign to this variable new content. What you want is to concatenate new list item with existing ones. This can be done using concatening assignment operator: $output .= '<li ...


0

Ok, first I'd ditch the output buffering. Second change: include(TEMPLATEPATH.'/wp-content/themes/grainandmortar/inc_static/test.php'); To include( get_stylesheet_directory() . '/inc_static/test.php'); Finally, Reading the documentation here: https://codex.wordpress.org/Shortcode_API You need to return something, if your test.php doesn't output ...


1

Here's another way to do it, utilizing get_template_part of wordpress function include_file($atts) { $a = shortcode_atts( array( 'slug' => 'NULL', ), $atts ); if($slug != 'NULL'){ ob_start(); get_template_part($a['slug']); return ob_get_clean(); } } add_shortcode('include', 'include_file'); ...



Top 50 recent answers are included