I’m getting a weird behavior from the wp admin bar when logged in. Let me explain. My project has a custom permalink structure with a string before the post name (like custom-string/%postname%/) set in the permalink settings. This works ok for posts and CPT’s, but not for pages. So, to get this working for pages, I added this code sample in my functions.php file:

add_action( 'init', 'custom_page_rules' );
add_filter( 'post_link', 'change_page_links', 1, 3 );
function custom_page_rules() {
    global $wp_rewrite;
    $wp_rewrite->page_structure = $wp_rewrite->root . 'my-string/%pagename%'; 
function change_page_links( $post_link, $id=0 ){
    $post = get_post($id);
    if( is_object($post) && $post->post_type == 'page'){
        return home_url('/my-string/'. $post->post_name.'/');
    return $post_link;

This code sample works, and now my pages and all links using the_permalink() or get_permalink() are working fine with the desired string. But, when I set this code, the admin bar stopped showing for all pages (including posts and CPT’s single pages), except for the home page, which doesn’t have the string added to the permalink.

The website works ok, and I got no errors when set define( 'WP_DEBUG', true );. If I remove the code sample, the admin bar starts to show again.

What could be causing this behavior? Any tips on how to solve this?


Read more here: WP Admin Bar not showing with custom permalink structure for pages


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: