Tagged: blog titles, Custom Post Type, functions
-
AuthorPosts
-
July 22, 2016 at 11:13 pm #664089
Hi,
So first I will start by saying that I have added the code to the functions file to change the title of the blog from “Blog – Latest News” to “Insights”. I have done that with this code.
`add_filter(‘avf_title_args’, ‘fix_single_post_title’, 10, 2);
function fix_single_post_title($args,$id)
{
if ( $args[‘title’] == ‘Blog – Latest News’ )
{
$args[‘title’] = Insights;
$args[‘link’] = get_permalink($id);
$args[‘heading’] = ‘h1’;
}return $args;
}`With that being said the main reason for my question is that I have also created a custom post type called counselors but now on the counselors single pages it’s also displaying that same “Insights” header. I did a search like normal to see what I can find and I found this thread.
https://kriesi.at/support/topic/custom-post-types-and/
She was basically looking to do the same thing as me so I tried to follow suit but im having no luck. Here is the code im using to try and change my custom post type title.
add_filter('avf_title_args', 'fix_single_post_title', 10, 2); function fix_single_post_title_2($args,$id) { if ( is_singular('post') || is_singular('counselors') ) { $args['title'] = get_the_title($id); $args['link'] = get_permalink($id); $args['heading'] = 'h1'; } return $args; }
I changed the the function name so it’s not the same as my first function to change my blog title and I put in my CPT slug where they said to do it but yea….its just not working.
Any help would be great.
Thanks
-Dan- This topic was modified 8 years, 3 months ago by acscreativenew.
July 25, 2016 at 10:24 pm #664869Hi,
Can you please create us a WordPress administrator account? post it here as a private reply.
Regards,
JosueJuly 25, 2016 at 10:33 pm #664875Here you go, thanks for the help
July 25, 2016 at 10:42 pm #664886Hi,
You were missing a
2
in the second filter:add_filter('avf_title_args', 'fix_single_post_title_2', 10, 2);
Best regards,
JosueAugust 11, 2016 at 7:58 pm #671545Hi,
So I thought I had this working right but it turns out I don’t.
When you are on this page.
The title is right, but when you click into a post it says this.
This is the title for my CPT I added in.
Any guidance?
Thanks
-DanAugust 12, 2016 at 3:45 am #671635Hi,
The second link you posted is returning a 404 error.
Best regards,
JosueAugust 12, 2016 at 4:32 am #671656Odd, i am not getting that
August 12, 2016 at 3:20 pm #671850Hi,
What title should be there? the login access you provided aren’t working.
Best regards,
JosueAugust 12, 2016 at 3:26 pm #671852The same title that is on the first page. Insights is what the blog index page says but when you go into the blog post page it goes back to Counselors.
Here is the code
// Change Blog Title add_filter('avf_title_args', 'fix_single_post_title', 10, 2); function fix_single_post_title($args,$id) { if ( $args['title'] == 'Blog - Latest News' ) { $args['title'] = Insights; $args['link'] = get_permalink($id); $args['heading'] = 'h1'; } return $args; } // Change CPT Title add_filter('avf_title_args', 'fix_single_post_title_2', 10, 2); function fix_single_post_title_2($args,$id) { if ( is_singular('post') || is_singular('counselors') ) { $args['title'] = Counselors; $args['link'] = get_permalink($id); $args['heading'] = 'h1'; } return $args; }
I just added another custom post type that im going to need to do this too also.
I have it working here This is a custom post type post page, there is not index page for this post type.
But here are two other CTP that I need it working on correctly
This is the main default wordpress “post” I just have changed the name of it
Default post with name changed
So technically i am using the default “post” with a changed name and also have two custom post types
August 12, 2016 at 4:01 pm #671870Hi,
Instead of those snippets i’d suggest using something like this:
add_filter('avf_title_args', 'fix_single_post_title_2', 10, 2); function fix_single_post_title_2($args,$id) { if ( is_singular('post') || is_page(12) ) { // 12 being Page ID of the blog index $args['title'] = 'Insights'; } elseif ( is_singular('counselors') ) { $args['title'] = 'Counselors'; } elseif ( is_singular('another_ctp') ) { $args['title'] = 'Another CPT'; } else { $args['title'] = 'Default Title'; } return $args; }
Best regards,
JosueAugust 12, 2016 at 4:23 pm #671882So I think this might be a set in the right direction but after i did this all the titles of my other pages changed to Default Title? They need to remain the title given to them.
Like this one would be “About Us”
August 12, 2016 at 8:39 pm #672054Then simply leave that part empty:
}else{ }
Best regards,
JosueAugust 12, 2016 at 8:49 pm #672060Perfect. Thank you.
August 12, 2016 at 9:08 pm #672064You are welcome, glad to help :)
Regards,
Josue -
AuthorPosts
- You must be logged in to reply to this topic.