Tag Info

Hot answers tagged

16

As an extension to @G.M. answer (which is the only possible way to do this), here's a slightly shortened/beautified and and an extended version (which I personally prefer): Shortened/Beautified variant It's enough to do a boolean check for the contained value. If it's true, the result will be (bool) true, else it will be false. This produces a one case ...


6

Is easy to use 0 and 1 values and then typecasting inside the function: [shortcode boolean_attribute='1'] or [shortcode boolean_attribute='0'] but if you want you can also strictly check for 'false' and assign it to boolean, in this way you can also use: [shortcode boolean_attribute='false'] or [shortcode boolean_attribute='true'] Then: add_shortcode( ...


5

Filter the_category, and remove those attributes: add_filter( 'the_category', 't5_remove_cat_rel' ); function t5_remove_cat_rel( $list ) { return str_replace( array ( 'rel="category tag"', 'rel="category"' ), '', $list ); }


4

It turns out WordPress shortcode system uses function shortcode_parse_atts($text); to parse a shortcode entry to retrive attributes' names and values and store them in pairs in the array $atts, which is then passed to the shortcode function. So in your case adding escaping actions in the shortcode function like this: $aps_person_description = ...


4

I'm trying to do this right now as well. The filter function seems like the best bet. This is where I'm at now, but I can't seem to get the title of the next or previous post and pass it to the filter. Edit: Figured it out. A bit hackey probably, but it works. add_filter('next_post_link','add_title_to_next_post_link'); function ...


4

instead of replacing the alt tag you could add-an-attribute-to-a-tag function add_lazyload($content) { $dom = new DOMDocument(); @$dom->loadHTML($content); foreach ($dom->getElementsByTagName('img') as $node) { $oldsrc = $node->getAttribute('src'); $node->setAttribute("data-original", $oldsrc ); ...


4

if you set image size in function.php as a "gallery" add_image_size( 'gallery', 200, 120, true ); you can remove width and height of specific image size such as "gallery": add_filter('wp_get_attachment_link', 'remove_img_width_height', 10, 4); function remove_img_width_height( $html, $post_id, $post_image_id,$post_thumbnail) { if ...


4

Without seeing your code it is difficult to give you an exact answer. There is the shortcode_atts_{$shortcode} filter that was introduced in Wordpress 3.6. All attributes is run through this filter. It has to be noted that the $shortcode parameter needs to be set in shortcode_atts. I haven't seen shortcodes yet that has this parameter set though. Your ...


3

Here's just an addition to the answer by @PieterGoosen. There are few methods how one could modify the post type of WP_Query, that's inside a shortcode. Let's assume it's [recent_posts]. Method A) If the shortcode uses the third parameter of the shortcode_atts() (as @PieterGoosen mentioned) for example wpse, then: /** * Method A: Using the ...


3

I haven't actually tested this, but came across the following code on my travels. Might this help? get_post_meta($attachment_id, '_wp_attachment_image_alt', true)


3

You might have better luck using wp_get_attachment_url( $id ) rather than wp_get_attachment_image(). Take a look at the WordPress codex for the call.


3

I modified peteroak's excellent solution to convert to utf-8 and stripped the doctype, html, and body from the ouput. function add_lazyload($content) { $content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8"); $dom = new DOMDocument(); @$dom->loadHTML($content); foreach ($dom->getElementsByTagName('img') as $node) { ...


3

There is a new shortcode_atts_{$shortcode} filter in WordPress 3.6 according to Mark Jaquith. You could use the shortcode_atts_gallery filter to force the link='file' attribute: add_filter('shortcode_atts_gallery','overwrite_gallery_atts_wpse_95965',10,3); function overwrite_gallery_atts_wpse_95965($out, $pairs, $atts){ // force the link='file' gallery ...


3

You can hijack the shortcode handler and set the attribute to a value of your choice. Then call the native callback for this shortcode. add_shortcode( 'gallery', 'file_gallery_shortcode' ); function file_gallery_shortcode( $atts ) { $atts['link'] = 'file'; return gallery_shortcode( $atts ); }


3

Update As I deleted the Repo on GitHub, here's a new answer. add_filter( 'previous_post_link', 'wpse13044_adjacent_post_link_tooltip', 10, 2 ); add_filter( 'next_post_link', 'wpse13044_adjacent_post_link_tooltip', 10, 2 ); function wpse13044_adjacent_post_link_tooltip( $format, $link ) { $previous = 'previous_post_link' === current_filter(); // Get ...


2

Not exactly wordpress question, more of a php but - The syntax for echo is quit simple : You start with a quotation mark, and close with a quotation mark. But since INSIDE the HTML we also need quotation marks , we separate them by using the single ' for PHP and the double " for HTML. every time you have a php function, command, or variable, you should ...


2

What is 'two' referring to? Is that a custom image size? Place the following var_dump('<pre>',$image,'</pre>'); after your declared $image variable like so, $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'two' ); var_dump('<pre>',$image,'</pre>'); and provide the results so we can inspect the output. ...


2

You might try something like this in your functions.php: //remove class from the_post_thumbnail function the_post_thumbnail_remove_class($output) { $output = preg_replace('/class=".*?"/', '', $output); return $output; } add_filter('post_thumbnail_html', 'the_post_thumbnail_remove_class');


2

include changes the scope. You would need to declare $classslider global before defining it, and then use global $classslider; before using it. function bf_shortcode_slideshow($atts) { global $classslider; extract(shortcode_atts(array( ... I think that will fix your problem. I don't understand why you are using include at all though. There must be a ...


2

When I test get_the_post_thumbnail (also the_post_thumbnail) on WordPress 3.5.1, the alt attribute is added as it should be. If you look at the source, you will see that get_the_post_thumbnail uses wp_get_attachment_image which does add that alt attribute. By default, that attribute is the image file name but it can be edited from wp-admin->Media to be ...


2

Use 0 and 1 as shortcode values and use that show or hide the HTML attribute. Example with an element input and the attribute required: function input_shortcode( $atts ) { $values = shortcode_atts( array ( 'type' => 'text', 'value' => '', 'name' => '', 'id' => '', ...


2

This should work for the rel attribute: /** * Create a rel attribute from the image categories * * @see http://wordpress.stackexchange.com/a/158024/26350 */ add_filter( 'get_image_tag', function( $html, $id ) { $rel = array(); foreach( (array) get_the_category( $id ) as $cat ) { $rel[] = $cat->slug; ...


2

Untested (and can't test right now) but you ought to be able to add attributes with a filter... something like: function test_sc($atts,$content) { // echo 'test_sc'; $atts = shortcode_atts( array( 'foo' => 'no foo', 'bar' => 'default bar', ), $atts, 'testsc' ); // var_dump($atts); } ...


1

I found a solution with a recursive function function decomposePrice($base, $iValue, $values, $prices) { $d = array(); foreach ($prices as $i => $p) { $baseP = "$base{$values[$iValue][$i]}|"; if (!is_array($p)) { $d[$baseP] = $p; } else { $d = array_merge($d, decomposePrice($baseP, $iValue + 1, ...


1

You should try this on a default theme (without any plugins), to see if that makes any difference. Your shortcode example: [caption id="my-caption-id" class="my-caption-class" align="alignnone" width="399"] <img src="whatever.jpg" alt="whatever" width="399" height="600" /> My caption text [/caption] gives this output: <div ...


1

I ended up modifying slightly to use data-filter instead of rel. Works perfectly and complies with standards. add_filter( 'get_image_tag', function( $html, $id ) { $dataFilter = array(); foreach( (array) get_the_category( $id ) as $cat ) { $dataFilter[] = $cat->slug; } return str_ireplace( ...


1

You need to use the hooks attachment fields to edit / save to ad and save the fields. function add_attachment_field_credit( $form_fields, $post ) { $form_fields['paper-type'] = array( 'label' => 'Paper type', 'input' => 'text', 'value' => get_post_meta( $post->ID, 'paper_type', true ), 'helps' => 'Photo ...


1

Depending on how your Galleria plugin is interacting with the attachment image filters, you should be able to inject your data attribute using the wp_get_attachment_image_attributes filter. Obviously, the attribute would be added for anything using wp_get_attachment_image(), but it will do what you're asking. /** * Filter attributes for the current ...


1

Don't try to shove everything into a single attribute, or a single shortcode even. The string parsing you have to do will get more and more complicated. Try this: function myshortcode_cb( $atts ) { $atts = shortcode_atts( array( 'cat' => '', 'title' => '' ), $atts ); // var_dump($atts); // debug return ...


1

How about just assign a default image to this variable? So if no image is specified a default (instead of empty) image url is used? BTW. What's with those backslashes? Just use single and double quotes. function button_shortcode($args) { extract(shortcode_atts($default=array( 'url' => 'http://default.com', 'bigtext' => 'Your ...



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