Tag Info

Hot answers tagged

12

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

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

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


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

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


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.


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

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

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

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

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


1

Find the line /* Remove [caption] in-line styling in function.php. Comment out: /* add_shortcode('wp_caption', 'fixed_img_caption_shortcode'); add_shortcode('caption', 'fixed_img_caption_shortcode'); function fixed_img_caption_shortcode($attr, $content = null) { // Allow plugins/themes to override the default caption template. $output = ...


1

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' => '', ...


1

Nameless attributes are still getting passed to shortcode handler, they just can't be accessed by name (because, duh!) You could loop through attributes with numeric keys and check for presence of autoplay value, thus achieving [video autoplay] variant. See similar question - Shortcode But Without The Equals Sign?


1

You can check out esc_attr() Encodes the <, >, &, " and ' (less than, greater than, ampersand, double quote and single quote) characters. Will never double encode entities. http://codex.wordpress.org/Function_Reference/esc_attr


1

It seems you are working on the wrong end. Try sanitizing the user input, for instance by means of sanitize_textfield, not the shortcode output.


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


1

Okay, I've re-written the function so that it does the following: checks that your array values are set before using them. You can't always be sure they'll be there. if the image is empty, it returns with an error message. Not sure if this is what you want, but you can just remove it. first creates your image html. then, if there's a URL specified, it ...


1

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


1

A bit old perhaps, and I wasn't really sure on how to make a comment on a reply... In short, after looking for the same solution I've modified Picard102's suggestion just a tiny bit: /** * Filter previous_post_link and next_post_link */ function filter_next_post_link($link) { global $post; $post = get_post($post_id); $next_post = ...


1

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


1

You can also get the data for width and hight of a image. $src = wp_get_attachment_image_src( $attachment_id, 'full' ); var_dump($src); the var_dump output like this: array 0 => string 'http://example.com/wp-content/uploads/2009/08/DSC00261.JPG' (length=63) 1 => int 1632 2 => int 1224 3 => boolean false The results mean: $src[0] ...


1

Ok, I've never seen a shortcode done in this way so I threw together a bit of code to test your scenario. And I get the same results with code that works just fine with the standard shortcode format. Standard Shortcode Format [shortcode name1="value1" name2="value2"] I don't believe this is a result of wpautop(), but a result of the way the shortcode ...


1

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


1

As I guess what you're after (and which is off topic here), I'll briefly explain what is... The problem IE (versions 6, 7, and 8 and under its “compatibility mode”) will not render an image when that image has blank width and height attributes (...) So this code will produce no images in IE: <img src="logo.png" alt="company logo" width="" ...



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