概述
wordpress图像大小 WordPress allows users to place an image into page or post content. Typically, the following HTML code is produced: WordPress允许用户将图像放入页面或发布内容。 通常,将生成以下HTML代码: Nothing too horrific, but what if you want to: 没什么太可怕的,但是如果您想: Fortunately, WordPress provides a couple of filter functions to help you modify the HTML. They can be placed in your theme’s functions.php file or within a plug-in. 幸运的是,WordPress提供了一些过滤器功能来帮助您修改HTML。 它们可以放置在主题的functions.php文件中或插件中 。 Unlike other WordPress content filters, <img> tags are generated when the editor inserts the image into the post. Therefore, these functions will not change code for images which have already been added to a post. 与其他WordPress内容过滤器不同,<img>标签是在编辑器将图像插入帖子时生成的。 因此,这些功能将不会更改已添加到帖子中的图像的代码。 Therefore, the only way to test your code is to repeatedly add and remove images. I recommend switching to WordPress’s HTML view to check the result. 因此,测试代码的唯一方法是重复添加和删除图像。 我建议切换到WordPressHTML视图以检查结果。 The easiest and most commonly used filter is for the image class: 最简单,最常用的过滤器是图像类: The image_tag_class() function accepts 4 string parameters: the existing class, the image ID (numeric), the alignment (none, left, right, center), and the size (normally ‘full’). It returns a string which will become the <img> tag class. In this example, we’re simply returning the alignment string. image_tag_class()函数接受4个字符串参数:现有类,图像ID(数字),对齐方式(无,左,右,居中)和大小(通常为“完整”)。 它返回一个字符串,该字符串将成为<img>标记类。 在此示例中,我们仅返回对齐字符串。 If we need to make fundamental changes to the <img> tag, we need a filter which can modify the returned HTML directly using string or regular expression replacements, e.g. 如果需要对<img>标签进行根本性的更改,则需要一个过滤器,该过滤器可以使用字符串或正则表达式替换直接修改返回HTML,例如 The image_tag() function accepts 4 string parameters: the generated HTML, the image ID (numeric), the alt and title text. In this example, we’ve stripped the domain name from the src URL, removed the height and width attributes and replaced empty alt attributes with the title text. You can change the function accordingly for your own substitutions. image_tag()函数接受4个字符串参数:生成HTML,图像ID(数字),alt和标题文本。 在此示例中,我们从src URL中删除了域名,删除了height和width属性,并将空的alt属性替换为标题文本。 您可以相应地为自己的替换功能。 While HTML <img> tag modification is not something you’ll need every day, it’s useful to know that WordPress supports the feature. 尽管HTML <img>标记修改并不是您每天都需要的,但了解WordPress支持该功能很有用。 翻译自: https://www.sitepoint.com/wordpress-change-img-tag-html/ wordpress图像大小<img src="http://www.mysite.com/wp-content/uploads/2011/07/myimage.jpg"
alt="my image" title="my image title"
width="100" height="100" class="aligncenter size-full wp-image-123" />
更改图像类别 (Changing the Image Class)
function image_tag_class($class, $id, $align, $size) {
return $align;
}
add_filter('get_image_tag_class', 'image_tag_class', 0, 4);
先进的图像修改 (Advanced Image Modification)
function image_tag($html, $id, $alt, $title) {
return preg_replace(array(
'/'.str_replace('//','//',get_bloginfo('url')).'/i',
'/s+width="d+"/i',
'/s+height="d+"/i',
'/alt=""/i'
),
array(
'',
'',
'',
'alt="' . $title . '"'
),
$html);
}
add_filter('get_image_tag', 'image_tag', 0, 4);
最后
以上就是结实战斗机为你收集整理的wordpress图像大小_如何更改WordPress帖子中的图像属性的全部内容,希望文章能够帮你解决wordpress图像大小_如何更改WordPress帖子中的图像属性所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复