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


7

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

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


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


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


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

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

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

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


2

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


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

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

Yes you can. See my working fiddle here: http://jsfiddle.net/MonkimoE/0wtgm8a1/ You need to add an id. example: <img class="img" id="imageid"..... Delete all atribute "data-width" and "data-height". because it will added automatically. Add this javascript: (you may change the '$' to 'jQuery' if doesn't work with your theme) <script> var ...


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


2

First of all i'd recommend you stop using title attribute for html container purpose: Image title (and the element name speaks for itself) should provide additional information and follow the rules of the regular title: it should be relevant, short, catchy, and concise (a title “offers advisory information about the element for which it is set“). ...


1

As per what I understood from your question, you want two things - Listing of all publisher Listing of all books of a particular publisher. Here is code for both. Listing of all publisher $terms = get_terms( 'pa_publisher' ); echo '<ul>'; foreach ($terms as $each_term) { echo '<li>'.$each_term->name.'</li>'; } echo ...


1

WordPress default importer will not work for WooCommerce product attributes. There is a plugin available to import WooCommerce products which handles import for products as well as their attributes. I'll not paste the plugin URL here since it's a third party plugin, but if you google for 'WooCommerce import', you will easily get that plugin.


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