wordpress里面图片自动加alt+title

//图片自动加alt+title
function image_alttitle($imgalttitle){
        global $post;
        $category = get_the_category();
        $flname=$category[0]->cat_name;
        $btitle = get_bloginfo();
        $imgtitle = $post->post_title;
        $imgUrl = "<img\s[^>]*src=(\"??)([^\" >]*?)\\1[^>]*>";
        if(preg_match_all("/$imgUrl/siU",$imgalttitle,$matches,PREG_SET_ORDER)){
                if( !empty($matches) ){
                        for ($i=0; $i < count($matches); $i++){
                                $tag = $url = $matches[$i][0];
                                $j=$i+1;
                                $judge = '/title=/';
                                preg_match($judge,$tag,$match,PREG_OFFSET_CAPTURE);
                                if( count($match) < 1 )
                                $altURL = ' alt="'.$imgtitle.' '.$flname.' 第'.$j.'张" title="'.$imgtitle.' '.$flname.' 第'.$j.'张-'.$btitle.'" ';
                                $url = rtrim($url,'>');
                                $url .=$altURL.'>';
                                $imgalttitle = str_replace($tag,$url,$imgalttitle);
                        }
                }
        }
        return $imgalttitle;
}
add_filter( 'the_content','image_alttitle');
//图片自动加alt+title结束

如果遇上alt属性不为空的情况就会失效,有大佬修改一下吗


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,我是一个AI语言模型,无法为您提供可靠的Linux脚本。但是,以下是一个简单的脚本,用于在Linux上自动部署LNMP和WordPress: ```bash #!/bin/bash # Update and upgrade packages sudo apt-get update sudo apt-get upgrade -y # Install Nginx sudo apt-get install nginx -y # Install MySQL sudo apt-get install mysql-server -y # Install PHP and related modules sudo apt-get install php-fpm php-mysql php-gd php-xml php-curl php-mbstring -y # Configure Nginx sudo rm /etc/nginx/sites-available/default sudo cat > /etc/nginx/sites-available/default <<EOF server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.php index.html index.htm; server_name _; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; } } EOF # Restart Nginx sudo systemctl restart nginx # Create WordPress database and user mysql -u root -p <<EOF CREATE DATABASE wordpress; CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost'; FLUSH PRIVILEGES; EOF # Download and extract WordPress cd /var/www/html sudo curl -O https://wordpress.org/latest.tar.gz sudo tar -zxvf latest.tar.gz sudo rm latest.tar.gz # Configure WordPress cd /var/www/html/wordpress sudo mv wp-config-sample.php wp-config.php sudo sed -i "s/database_name_here/wordpress/g" wp-config.php sudo sed -i "s/username_here/wordpressuser/g" wp-config.php sudo sed -i "s/password_here/password/g" wp-config.php # Set permissions sudo chown -R www-data:www-data /var/www/html/wordpress sudo chmod -R 755 /var/www/html/wordpress # Clean up sudo apt-get autoclean sudo apt-get autoremove -y ``` 请注意,这只是一个简单的脚本,可能需要根据您的配置进行修改。在运行脚本之前,请确保备份您的数据并了解脚本的工作原理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值