首页 > 解决方案 > 如何设置 wordpress the_title 的最大长度?

问题描述

我想在 WordPress 高级自定义字段中设置标题的最大长度。

我这样使用但它不起作用:

<p style="position:relative;top:-30px;">    
    <?php
     $post_object_th = get_field('therapeutic_class');
     if( $post_object_th ): 
       $post = $post_object_th;
       setup_postdata( $post ); 
       $g_name = get_the_title();               
     endif;
    wp_reset_postdata();
    ?>
    <?php echo wp_trim_words( $g_name, 1 ); ?>
 </p>

标签: phpwordpressadvanced-custom-fieldsmaxlength

解决方案


我得到了答案只需使用这个 php 函数substr()

<?php echo substr($g_name,0,10).'...';?>

推荐阅读