Truncate title page in the admin dropdown list
-
Hello,
I have a huge problem. Titles of my pages are very (very) long. So in the admin backend, when I want to attribute a parent page to the new one that I want to create… it’s impossible !
I must go to right to dropdown the selection menu (whitch display erevy pages) and I can’t see anymore the parent pages on the left !
Did someone know how to truncate title here and not in the hole site ?
I have try the plugin truncate title but I haven’t succed to make it truncate the admin title in the dropdown menu…
At this time, I can’t use anymore the pages fonction. ??
Plzz Help
-
I have seen people who write “Four score and twenty years ago…” titles and those are not titles, they are posts without titles ;-). I’d love to see some of yours, how about a link?
As for your issue, you’d have to truncate the title in the core files (and it probably wouldn’t be pleasant).
Might be easier to give a small title and in the template display a separate title “if is_page(‘short-title’)”
I can’t because titles are scientific article titles, and so they must have a certain form. You can see the problem on public side here :
https://www.cometes.org/index.php
(all is manage with wordpress)
The “num??ros” of the revue are “Pages” : https://www.cometes.org/revue/numeros/
Do you know how to fix ? I’m trying since 2 days and I don’t succed :-(.
Your situation may be different than mine, but back in the day when I was writing and reading scientific articles, they were long titles but had a shorter main title with a longer subtitle. If that is the case, you could have a shorter title and put the subtitle in the custom meta section to display just beneath the title…
Hypoth?¨se et fiction :
les relations complexes de deux discours. Quelques remarques sur les strat??gies discursives de J.-B. Robinet dans la philosophie de son temps, Nathalie VuilleminNo. It’s not possible, because when title are display at another place in the site, they must be complete. University has got rigid codes that we can’t break.
Here is apparently the function whitch displays the pages tree :
function parent_dropdown($default = 0, $parent = 0, $level = 0) {
global $wpdb, $post_ID;
$items = $wpdb->get_results(“SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_status = ‘static’ ORDER BY menu_order”);if ($items) {
foreach ($items as $item) {
// A page cannot be it’s own parent.
if (!empty($post_ID)) {
if ($item->ID == $post_ID) {
continue;
}
}
$pad = str_repeat(‘ ‘, $level * 3);
if ($item->ID == $default)
$current = ‘ selected=”selected”‘;
else
$current = ”;echo “\n\t<option value=’$item->ID’$current>$pad $item->post_title</option>”;
parent_dropdown($default, $item->ID, $level + 1);
}
} else {
return false;
}
}in admin-functions.php
Now the challenge is to truncate… Oulala !…I was confused. Not sure why you are making the articles each be a page rather than post them as articles (posts) to particular pages, but there was my confusion.
As posts, they don’t have to be displayed at another place. I have used them like this. Wherever you use the_title(), you can make it the_title() the_meta().
In the echo line you posted above, I suppose if you can remember to check the page id you want to be the parent, you could change the parent_dropdown function to display the ID and not the post_title.
Yes it’s a solution, but not “clean”. I want something more intuitive for authors. You think it’s technicaly impossible to truncate titles generate by this function ?
No but when taking a look at it I decided it would not be easy for moi
Yes. I have try to apply the truncate title function (from the same name plugin) to this wp-function, but it doesn’t work… :
function tronquer_admin_titres($admin_titre) {
$MAX_LENGTH = 45;
$TERMINATOR = ‘ …’;if(strlen($admin_titre) > $MAX_LENGTH){
$parts = explode(‘ ‘, $admin_titre);
$admin_titre = “”;
$i = 0;while(strlen($admin_titre) < $MAX_LENGTH && $i < count($parts)){
if(strlen($parts[$i]) + strlen($admin_titre) > $MAX_LENGTH){
return $admin_titre . $TERMINATOR;
} else {
$admin_titre .= ‘ ‘ . $parts[$i];
$i++;
}
}return $admin_titre . $TERMINATOR;
} else{
return $admin_titre;
}
}add_filter(‘the_title’, ‘tronquer_admin_titres’);
(I have change names to not truncate every titles in my site !)
So with this function in an activate plugin, I have change in admin-function.php the original parent_dropdown function with :
function parent_dropdown($default = 0, $parent = 0, $level = 0) {
global $wpdb, $post_ID;
$items = $wpdb->get_results(“SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_status = ‘static’ ORDER BY menu_order”);if ($items) {
foreach ($items as $item) {
// A page cannot be it’s own parent.
if (!empty($post_ID)) {
if ($item->ID == $post_ID) {
continue;
}
}
$pad = str_repeat(‘ ‘, $level * 3);
if ($item->ID == $default)
$current = ‘ selected=”selected”‘;
else
$current = ”;////////////////////////////////////////////////////:
$item = tronquer_admin_titres($item);
/////////////////////////////////////////////////////echo “\n\t<option value=’$item->ID’$current>$pad $item->post_title</option>”;
parent_dropdown($default, $item->ID, $level + 1);
}
} else {
return false;
}
}I’m not a code killer, so it can be simply a quote problem ! I just touch and look… since the beginning.
Yeeeeees ! I’m simply the best. See :
To truncate pages titles in the admin dropdown menu, make this :
1. Put this function in a plugin called “heisthebest.php” :
function tronquer($admin_titre) {
$MAX_LENGTH = 45;
$TERMINATOR = ‘ …’;if(strlen($admin_titre) > $MAX_LENGTH){
$parts = explode(‘ ‘, $admin_titre);
$admin_titre = “”;
$i = 0;while(strlen($admin_titre) < $MAX_LENGTH && $i < count($parts)){
if(strlen($parts[$i]) + strlen($admin_titre) > $MAX_LENGTH){
return $admin_titre . $TERMINATOR;
} else {
$admin_titre .= ‘ ‘ . $parts[$i];
$i++;
}
}return $admin_titre . $TERMINATOR;
} else{
return $admin_titre;
}
}(thanks to truncate title plugin : https://dev.wp-plugins.org/browser/truncate-title/ / I have only change some parameters names and erase the last line whitch make bugs in our case)
2. Activate the plugin !
3. Go in wp-admin/admin-functions.php and replace this function :
function parent_dropdown($default = 0, $parent = 0, $level = 0) {
global $wpdb, $post_ID;
$items = $wpdb->get_results(“SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_status = ‘static’ ORDER BY menu_order”);if ($items) {
foreach ($items as $item) {
// A page cannot be it’s own parent.
if (!empty($post_ID)) {
if ($item->ID == $post_ID) {
continue;
}
}
$pad = str_repeat(‘ ‘, $level * 3);
if ($item->ID == $default)
$current = ‘ selected=”selected”‘;
else
$current = ”;echo “\n\t<option value=’$item->ID’$current>$pad $item->post_title</option>”;
parent_dropdown($default, $item->ID, $level + 1);
}
} else {
return false;
}
}whith this one :
function parent_dropdown($default = 0, $parent = 0, $level = 0) {
global $wpdb, $post_ID;
$items = $wpdb->get_results(“SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_status = ‘static’ ORDER BY menu_order”);if ($items) {
foreach ($items as $item) {
// A page cannot be it’s own parent.
if (!empty($post_ID)) {
if ($item->ID == $post_ID) {
continue;
}
}
$pad = str_repeat(‘ ‘, $level * 3);
if ($item->ID == $default)
$current = ‘ selected=”selected”‘;
else
$current = ”;// HAPAX CHANGES
$titre = $item->post_title;
$titre = tronquer($titre);echo “\n\t<option value=’$item->ID’$current>$pad $titre</option>”;
parent_dropdown($default, $item->ID, $level + 1);// FIN HAPAX CHANGES
}
} else {
return false;
}
}And now you have a great little select menu of your pages titles ! ??
- The topic ‘Truncate title page in the admin dropdown list’ is closed to new replies.