如何通过php代码wordpress按字符缩短我的标题长度 [英] How to shorten my title lenth by characters via php code wordpress

查看:29
本文介绍了如何通过php代码wordpress按字符缩短我的标题长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想缩短相关帖子的标题长度,我尝试了几种变体,但没有一个有效.我现在有这个

I want to trim my title length on related posts and i tried several variations and no one works. I have now this

<p style="margin-top:-4px !important"><a class="title"  href="<?php the_permalink() ?>" title="<?php the_title(); ?>">**<?php echo short_title('...', 3); ?>**</a></p>

</li>
<?php

这个 short_title 修剪单词(现在我有值 3 它向我显示前 3 个单词),我只想要字符 20,30 .我该怎么做?

This short_title trims words(now i have value 3 it shows me first 3 words) and I want just characters maybe 20,30 . How do I do this?

推荐答案

使用 substr()

Use substr()

$title = 'some text here for example';
$newTitle =  (strlen($title)>20)?substr($title,0,20):$title;

这篇关于如何通过php代码wordpress按字符缩短我的标题长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆