Tag Info

New answers tagged

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 ...


0

There was some weird issue with how Wordpress was handling line-breaks and auto styling between the shortcodes. After some more playing around was able to eliminate the issue. Very finicky system...


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 ...


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' ); ...


0

Ok, so I rewrote the gallery shortcode function by copying the original and removing/adding/changing what I needed, and now I share it with you. The major things I added/changed are: One single UL/LI list per gallery instead of a DL for each damned item.. Removed 'itemtag' attr, since there's no point in using another tag for items inside an UL 'icontag' ...


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

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).


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

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

I found this : http://richjenks.com/wp-shortcode-attributes-without-values/ CODE function get_flags($atts) { $flags = array(); if (is_array($atts)) { foreach ($atts as $key => $value) { if ($value != '' && is_numeric($key)) { array_push($flags, $value); } } } return ...


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(); ...


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 ...


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

Your ampersand is getting encoded, try: get_page_by_title( html_entity_decode( $title ) );


0

You can capture the list in a variable, rather than echo it: $list = '<ul class="strong"> <li>' . get_field( 'highlights_list_item#1' ) . '</li> <li>' . get_field( 'highlights_list_item#2' ) . '</li> </ul>'; echo do_shortcode( '[one_half]' . $list . '[/one_half]' ); Note the use of get_field() ...


1

It seems you need a seft-closing shortcode. http://codex.wordpress.org/Shortcode_API will be a great read to get started.


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 ...


0

This answer and question turns out to be polylang specific - the answer is a settings in the plugin: Settings > Languages > Settings Unchecking this option stops polylang looking for a translation specific version of the embedded media - in this case the [gallery]


0

A friend pointed out how to solve this. If anybody else runs into the same issue as me, this is the correct code. // Custom shortcode, to query tracklistings. function custom_query_shortcode($atts) { // Defaults extract(shortcode_atts(array( "the_query" => '' ), $atts)); // de-funkify query $the_query = preg_replace('~&#x0*([0-9a-f]+);~ei', ...


0

You simply need to query your custom fields and return them with your shortcode: // EXAMPLE USAGE: // [loop the_query="showposts=100&post_type=page&post_parent=453"] function custom_query_shortcode($atts) { // Defaults extract(shortcode_atts(array( "the_query" => '' ), $atts)); // de-funkify query $the_query = ...


0

The way your code is written, you are breaking your div tag over several lines-- literally like this, if you look at the generated source: <div class="Container-Caption" alt="Oh I have been to Ludlow Fair" rel="http://www.link.com"> blah</div> I do not see any different between using a caption with or without ...


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 ...


0

The easiest way is to use buffering. You might have already used ob_start() and ob_get_contents() PHP native function. So your code would be - ob_start(); if ( isset( $slug ) ) { .... rest of your code .... <?php endwhile; wp_reset_query(); $content = ob_get_contents(); return $content;


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)”) ...


0

What surprise me is that someone on May 2013, write a tutorial using extract and query_posts in same function. extract is considered a bad practice in PHP in general, and it's usage was abandoned also from WP core (it will no longer be used, but there are still extract calls in actual code). query_posts is a bad practice in WordPress world, you can read ...


0

Based on what you have above... I would change "numberposts" to "posts_per_page". And then I would change the "get_posts" to "new WP_Query" remove_shortcode( 'gallery' ); function gallery_filter( $atts, $content = null ) { extract(shortcode_atts(array('gallery_name' => ''), $args)); $args = array( 'post_type' => 'attachment', ...



Top 50 recent answers are included