Replace Dashes Before Title in Page List

I want to replace the dashes before the page title in the dashboard page list. For each hierarchy below the first, a dash is prepended (as seen in the screenshot below):

enter image description here

It seems that the filter the_title does not affect these dashes:

add_filter( 'the_title', 'change_my_title' );
function change_my_title( $title ) {
    return str_replace( '–', $title );
    // nor preg_replace or – or — work
}

So my question is: How can I replace these dashes with something specific? Do I really have to implement a custom list table or meddle around with jQuery?

4 Answers
4

You can’t change dashes using any filter because there is no filter available to change it.

but still you can change this using jQuery put this code inside functions.php

add_action('admin_head',function(){


global $pagenow;

// check current page.
if( $pagenow == 'edit.php' ){ ?>

    <script>

        jQuery(function($){

            var post_title = $('.wp-list-table').find('a.row-title');
            $.each(post_title,function(index,em){
                var text = $(em).html();
                // Replace all dashes to * 
                $(em).html(text.replace(/—/g ,'*'));
            });
        });

    </script>
    <?php
    }
});

See https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/class-wp-posts-list-table.php#L918-L919

Leave a Comment