• Resolved Javier Archeni

    (@javierarcheni)


    Hi Sybre! Congratulations for your awesome plugin. Pretty useful.

    One question, how can change title and description on archive custom post type pages?

    By default appears on title [Name of the custom post type + site name ]. For the descriptions appears the description name given in the register_post_type argument.

    Appreciate any help. Thanks.

    https://www.ads-software.com/plugins/autodescription/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hi Javier,

    Thanks :)!

    This depends on how the CPT archive has been set up.
    If it’s set up through a plugin, be sure to activate the Editor (content) and the Title fields for the CPT.

    If you used the register_post_type function, please see this topic:
    https://codex.www.ads-software.com/Function_Reference/register_post_type#supports
    Be sure to add title and editor support, from there the CPT should be available.

    If that doesn’t work, or you don’t want to do so, please try using the following filter:

    add_filter( 'the_seo_framework_supported_post_types', 'my_cpt_add_seo_settings' );
    function my_cpt_add_seo_settings( $types ) {
    
    	$types[] = 'my-cpt-type';
    	$types[] = 'my-other-cpt';
    
    	return $types;
    }

    I hope this helps, have a great day!

    Thread Starter Javier Archeni

    (@javierarcheni)

    Hi again Sybre, actually I already registered the cpt with support for title and editor, so your seo editor is working on the custom post type post.

    My question is about modifying the title and description for the archive page, or what’s the same, at showing this template archive-“custom-post-type-slug”.php. Is there any chance to modify title and description as in taxonomies?

    I tried using the new WordPress filter for the title pre_get_document_title (former wp_title), but I see your seo plugin takes precedence.

    Many thanks!!

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi Javier,

    I understand!
    The filter doesn’t work because The SEO Framework prevents others from altering the title at the init hook, but there are ways around this (i.e. get_header).
    Be sure to have title-tag support on your theme, otherwise pre_get_dopcument_title doesn’t work and you should then use the inconvenient wp_title filter.

    The following code should work when placed at the top of them template file, please note that it’s not tested and might contain syntax errors.

    <?php
    
    add_filter( 'the_seo_framework_description_output', 'my_custom_tsf_description' );
    add_filter( 'the_seo_framework_ogdescription_output', 'my_custom_tsf_description' );
    add_filter( 'the_seo_framework_twitterdescription_output', 'my_custom_tsf_description' );
    /**
     * Manipulate the description.
     *
     * @param string $description : Default ''
     *
     * @return string Description.
     */
    function my_custom_tsf_description( $description = '' ) {
    	$description = 'My Custom Description goes here.';
    
    	return $description;
    }
    
    add_action( 'get_header', 'my_custom_tsf_title_before', 1 );
    /**
     * Destroy and evade The SEO Framework's title buster.
     */
    function my_custom_tsf_title_before() {
    
    	if ( is_admin() || is_preview() )
    		return;
    
    	remove_all_filters( 'pre_get_document_title', false );
    
    	add_filter( 'pre_get_document_title', 'my_custom_tsf_title', 10 );
    	add_filter( 'the_seo_framework_ogtitle_output', 'my_custom_tsf_title' );
    	add_filter( 'the_seo_framework_twittertitle_output', 'my_custom_tsf_title' );
    	//* This one's tricky.
    	add_filter( 'wp_title', 'my_custom_tsf_title' );
    }
    
    /**
     * Manipulate the Title.
     *
     * @param string $title : Default ''
     *
     * @return string Title
     */
    function my_custom_tsf_title( $title = '' ) {
    
    	$title = 'My Custom Title goes here.';
    
    	return $title;
    }

    I hope this helps! ??

    Thread Starter Javier Archeni

    (@javierarcheni)

    Almost, almost done! Your code is working pretty fine except for the title ??

    I added support for title_tag in my theme and included the code in my custom plugin with other custom code for my theme (not in template as you suggested).

    I wrapped your functions in a conditional tag like this:

    if ( is_post_type_archive(array('cpt_marcas'))) {
    
    }

    Also I used wp_head action hook instead of get_header for the my_custom_tsf_title_before function.

    Everything is working fine (description and titles for og, twitter). Just the html title tag hasn’t changed. Be kind enough to check at https://asunoliver.com/marcas

    Thanks for your great support.

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi Javier,

    I used the get_header action hook for a good reason:
    It’s after init (where all filters get destroyed in The SEO Framework), yet before the title and the wp_head output.
    wp_head is (if done right) called after the title output.

    This should make the title change to your liking. If it doesn’t, please take a look at another working example right here.

    I hope this helps!

    Thread Starter Javier Archeni

    (@javierarcheni)

    Hi again Sybre, I understand now the reason you are using get_header hook instead of wp_head. I can’t yet figured out why the title is not changing accordingly.

    I tried using same come as the working example you sent (my mistake I didn’t see it before), but the result is the same. My last message using the wp_head hook is the best solution, since is only one page and I don’t want bother you more.

    Your Seo Plugin is working very fine for me in production. I even wrote a recomendation post in my own blog some days ago https://javierarcheni.com/blog/optimizacion-buscadores-wordpress-the-seo-framework/
    Of course, I rated your plugin 5 stars on www.ads-software.com.

    Thanks again for you help!!

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi Javier,

    Thank you so much for the amazing blog post and the review :).

    About the title not working, could you please check your header.php file, and see if there’s something along the following code in there?

    '<title>' . wp_title('') . '</title>'

    If that’s the case, I’d suggest removing that code and placing the following in your theme’s functions.php file:

    add_theme_support( 'title-tag' );

    As commented in the example code:

    //* This one's tricky.
    add_filter( 'wp_title', 'my_custom_tsf_title' );

    If you already have title-tag support and the code given isn’t working, could you send me the code used to generate the CPT and archives over at my contact page?

    Please also be aware that a much simpler filter is coming in the next update for all types of pages, on which you don’t have to disable and/or evade the Title Buster — and which conforms to your SEO settings.
    This should save us a lot of time :).

    No ETA is available yet for the update, but if all goes according to plan the Beta should be rolling out somewhere next week.

    I hope this helps and clears things up! Have a wonderful day!

    Thread Starter Javier Archeni

    (@javierarcheni)

    Hi Sybre, so glad to hear you liked the post. I found your plugin so useful I couldn’t refrain to write about it. You’re welcome!!

    For this site I’m using Sage from Roots.io This starter theme is including support for title-tag. This theme uses a wrapper to load the appropiate template from a base. Head is loaded from a template head.php which doesn’t change anything. I’m sending my cpt register code to your contact page, just for your consideration.

    Right now I’m fine with your plugin (just one page, but minor).

    Improvements in the plugin always sound good. Great.

    Thanks!!

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi Javier,

    Thanks for all the information.

    Sage seems to be up to date will the title standards. Your code looks fine too! I’m unsure why the title manipulation isn’t working with the given code.

    My suggestion would be to add the given code within the archive template file, but I understand that could be a problem with maintainability.

    However, as stated in my previous reply, a filter is underway. I hope that will be the solution for your needs, and of many others, of course :).

    Thank you for the patience and I hope you have a wonderful day!

    Thread Starter Javier Archeni

    (@javierarcheni)

    Hello Sybre, many thanks again for your incredible support. I’ll wait for your upcoming updates.

    Best regards!!

    Hi, was there ever a filter added? We need to have custom title tags for archive pages and I’m not seeing any way to do that currently.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Archive custom post type title description’ is closed to new replies.