How to rename the default posts-type Posts label for display on the front end

Hello,

I have several Custom Post Types and regular WP Posts all feeding into a main archive page called 'news'.

The CPT are for different areas but still under news and the core Posts are for the Blog.

I am using the below code to display the name of the post type on archive page excerpts (eg. events, awards). What I want to do is have the blog 'posts' display 'Blog' Instead of 'Posts' which they currently are doing.

<?php $post_type = get_post_type_object( get_post_type($post) ); echo $post_type->label ; ?>

Open in new window


I have renamed 'posts' to 'blog' in the admin area but it is still displaying 'posts' as the post type on the front end and I'm not sure how to change this.

Can anyone please advise how to fix this?

Thanks!
igloobobAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason C. LevineNo oneCommented:
Can you give us a link or a screenshot that illustrates the problem?  Having a hard time following this from text only.
0
igloobobAuthor Commented:
Hi Jason,
sure thing. Here is a screenshot, I have hidden all the actual post content but you can see here are 3 excerpts on my main news page. The news page shows all posts plus all my custom post types. Here you can see Events & Webcasts and Awards which are CPTs. Then there is one 'Posts' which is my regular posts. However, I have renamed these Blog for this website so I need to change this front end display from Posts to Blog.

I have Blog showing everywhere else back end and in the urls.

Does that make sense?

Thanks for taking a look.
Screen-Shot-2015-10-14-at-18.54.48.png
0
Jason C. LevineNo oneCommented:
So the blog posts are or are not a CPT?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

igloobobAuthor Commented:
no, the blog posts are the standard core WP 'posts', I just renamed them 'blog'.
0
Jason C. LevineNo oneCommented:
How did you do that?
0
igloobobAuthor Commented:
I added this to functions.php to change the labels in the admin area:

function edit_admin_menus() {
    global $menu;
     
    $menu[5][0] = 'Blog Posts'; // Change Posts to Blog Posts
}
add_action( 'admin_menu', 'edit_admin_menus' );

Open in new window


Then I changed the custom permalinks to:

/newsroom/blog/%postname%/

'newsroom' is my top level page on which I am displaying excertps from the blog (regular posts) and all the CPTs. So 'newsroom' is an archive for all those post types together. Then each of the post types has its own archive page.
0
Jason C. LevineNo oneCommented:
I figured it was something like that, thanks for confirming.

So that function changes the label in the admin, does nothing to the actual post type.  If you look in the wp-content table in the MySQL, you will see your blog posts still listed as "post" in there and that's why the front end continues to show "Posts"

Given what you have already done, I would simply create a new CPT for your Blogs and then use

https://wordpress.org/plugins/convert-post-types/

to migrate your posts to the blog CPT.  Trying to force WordPress do change its Posts to something else is a much harder fight, possibly an impossible one.
0
Jason C. LevineNo oneCommented:
I guess the other way to do it would be something like this:

<?php 
$post_type = get_post_type_object( get_post_type($post) ); 
if ( $post_type->label == "Post" ) { //or Posts or whatever it is.
     echo "Blog";
} else {
     echo $post_type->label ; 
}
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
igloobobAuthor Commented:
This worked a treat thank you! I think I might look to change it to a CPT as you suggested above but have one for the quick fix for now.

Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WordPress

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.