Tag Info

Hot answers tagged

4

You want to define a potentially huge number of different shortcodes with the same shortcode callback? Why don't you define a single shortcode, with a term attribute? For example [sc term="london"] ps: I think your problem lies in the $tax_term->name part, which could be a string like City of London and that's not a valid shortcode name. Try ...


4

I am doing something like this in one of my plugins: function my_body_class( $c ) { global $post; if( isset($post->post_content) && has_shortcode( $post->post_content, 'your-shortcode' ) ) { $c[] = 'your-class'; } return $c; } add_filter( 'body_class', 'my_body_class' ); I'm not sure it was really necessary, but I ...


4

Is there more efficient ways to validate the quotes using the WordPress api? I think you should set a nonce for the form You also should check if current user has capability to save quote To get properly sanitize values form $_POST look at filter_input and/or filter_input_array I don't see performance issues on validation, but a possible ...


2

the_field() is an ACF function and will echo content. It follows the WordPress (somewhat) pattern whereby functions with the_ at the front will echo content and functions beginning with get_ return content. Displays the value of the specified field. (this is the same as “echo get_field($field_name)”) ...


2

Parsing shortcodes from strings WordPress parses and replaces shortcodes from a piece of content via the do_shortcode function. This function, in turn, calls get_shortcode_regex, which returns the regular expression for matching shortcodes in a string. Using this function, we can get a list of all shortcodes ourselves: $pattern = get_shortcode_regex(); ...


2

Shortcodes must return, not echo or print their output. As the Codex entry for add_shortcode() explains: Note that the function called by the shortcode should never produce output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results. This is ...


1

In general Child Themes are meant to be used for customizations on upstream parent theme. However views differ for specific types of customizations. Since shortcodes are related to your content a lot, it might be more robust to considering putting them into simple plugin (or "must use" plugin).


1

You can use the the following attributes for the gallery shortcode: [gallery itemtag="ul" icontag="li" captiontag="li"] The problem with this is that the gallery shortcode wraps the image and the caption in different elements(thats why the default solution is using dl-dt-dd), so this will generate one li element for the image, and one for the caption. You ...


1

There are a lot of ays to do the trick, one possible is use a function that use a static variable. However, before you can be able to get the arguments set in shortcode, the shortcode must be processed... function foobar_func( $atts = array(), $out = FALSE ){ static $args = array( 'foo' => 'default foo', 'bar' => 'default bar' ); ...


1

Just define a variable, and concat all html as string and return it. <?php function services_shortcode( $atts ) { // Attributes extract( shortcode_atts( array( 'slug' => '', ), $atts ) ); $html=''; if ( isset( $slug ) ) { $args = array( 'post_type' => 'cbd_services', 'name' => $slug ); // -1 Shows ALL ...


1

Core shortcode Regular Expressions Basically we can do that with a Regex - actually even with the Regex provided by core by get_shortcode_regex(). First we need to grab the shortcode tags and build a regex. The core function get_shortcode_regex() sadly offers no chance to throw in an argument so we'd be left with a regex that matches each and every ...


1

While I am sure that this is theoritically possible, I am going to say "No, not really". If you look at the source, you can see that those brackets are hard-coded into a very complicated regex. I see no filters that will let you change that. The only reasonable way to approach this that I can think of would be: To remove the default shortcode system ...


1

remove_shortcode( 'gallery' ); add_shortcode( 'gallery', function( $atts ) { $atts = shortcode_atts( array( 'ids' => '' ), $atts ); return do_shortcode( "[wp-slideshow include=\"$atts[ids]\"]" ); } ); This may be better than replacing the gallery shortcode as if you decide to change plugin you will have the standard gallery shortcode which many ...


1

@MagentaCuda's solution is the simple solution and should function adequately. However, it does run the rather complicated shortcode regex twice, plus the additional processing of the do_shortcode() call. Both should be avoidable. You don't name the plugin you are using and a search reveals many possibilities that I don't have the time to dig through, so ...



Only top voted, non community-wiki answers of a minimum length are eligible