I am trying to make the project title accommodate titles of up to 4 lines with 4 different div tags. I think I'm really close but not sure what I'm doing wrong.
I went to settings->Front-End Content and added [get-char-count].
I added custom code for calc-length:
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
function func_get_char_count( $atts ) {
global $post;
If($atts['type']=="title") {
return strlen($post->post_title);
}else if($atts['type']=="post_type"){
return strlen($post->post_type);
}
return FALSE;
}
add_shortcode( 'get_char_count', 'func_get_char_count' );
Finally in the layout I have this code:
[wpv-conditional if="( '[get_char_count]' lte 22 )"]
<div class="white-project-name">[wpv-post-title]</div>[/wpv-conditional]
[wpv-conditional if="( '[get_char_count]' gte 23 ) AND ( '[get_char_count]' lte '51' )"]<div class="white-project-name-two-lines">[wpv-post-title]</div>[/wpv-conditional]
[wpv-conditional if="( '[get_char_count]' gte 52 ) AND ( '[get_char_count]' gte '76' )"]<div class="white-project-name-three-lines">[wpv-post-title]</div>[/wpv-conditional]
[wpv-conditional if="( '[get_char_count]' gte 77 )"]
<div class="white-project-name-four-lines">[wpv-post-title]</div>[/wpv-conditional]
which always choose the 1 option.
Should I pass the post id to my custom code (the $atts parameter)?
Hello,
I suggest you try these:
1) Modify your custom PHP codes as below:
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
function func_get_char_count( $atts ) {
global $post;
if(!isset($atts['type'])) {
return strlen($post->post_title);
}else if($atts['type']=="post_type"){
return strlen($post->post_type);
}
return FALSE;
}
add_shortcode( 'get_char_count', 'func_get_char_count' );
2)Since you are using custom shortcode [get_char_count] within [wpv-conditional] shortcode, please check these:
Dashboard-> Toolset-> Settings-> Front-end content
in section "Third-party shortcode arguments", add the your custom shortcode name: get_char_count
And test again.
More help:
https://toolset.com/documentation/user-guides/shortcodes-within-shortcodes
My issue is resolved now. Thank you!