Tag Info

Hot answers tagged

14

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

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


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


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

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


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


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

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


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

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

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

No need for functions and filters all you need to do is to use get_adjacent_post instead of next_post_link and prev_post_link, Note that get_adjacent_post is used to get previous and next post, you can read about it here To get previous post and it's title attribute use this $prev_post = get_adjacent_post(false, '', true); if(!empty($prev_post)) { echo ...


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.



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