• Resolved Jg

    (@adesignday)


    Site using Twig templates with Timber title and description Fix

    Working on a site for SEO hotfixes, WordPress site uses Twig templates, because of this TSF cannot change title and description of these custom pages.

    Is there a code or work around, to inject what I put into TSF settings.

    Regards
    Adam

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

    (@cybr)

    Hi Adam,

    Unfortunately, I have no experience with Twig.

    Could you tell me how you’ve registered the Timber-empowered pages, is this via a template file, or a Custom Post Type wrapper?

    To get you started, I think you’ll find these title and description filters helpful:

    
    /**
     * @param string     $title The title.
     * @param array|null $args  An array with 'id' and 'taxonomy' indexes.
     */
    add_filter( 'the_seo_framework_title_from_custom_field', function( $title, $args ) {
    	return $title;
    }, 10, 2 );
    
    /**
     * @param string     $desc The description.
     * @param array|null $args An array with 'id' and 'taxonomy' indexes.
     */
    add_filter( 'the_seo_framework_custom_field_description', function( $desc, $args ) {
    	return $desc;
    }, 10, 2 );
    

    Please double-check the canonical URL. If that’s invalid, you’d be better off disabling it.

    add_filter( 'the_seo_framework_rel_canonical_output', '__return_empty_string' );
    
    Thread Starter Jg

    (@adesignday)

    Hi Sybre,

    I believe these are done through a template file.

    Will give the above a try, and see what happens.

    Regards
    Ads

    Thread Starter Jg

    (@adesignday)

    Hi Sybre,

    Ok I have managed to fix the title doing it a different way, however on Custom post the decription needs to be taken from an ACF field through Twig shortcode is {{post.article_details_standfirst}}

    regrds
    Ads

    Thread Starter Jg

    (@adesignday)

    Hi Sybre,

    Ok I have figured out, that twig template intercepts the standard WP post with meta info from the twig template.

    I have disabled those in the twig template, so no longer displays duplicate meta info from both TSF and Twig. However I still need to have the post meta description to auto-populate from the data entred in the ACF field (StandFirst)Twig outputted the description using this shortcode for meta description {{post.article_details_standfirst}}

    Hope you can help, as the above functions that you supplied did not work.

    Kind Regards
    Ads

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi Adam,

    The filters I mentioned above need to before the action ‘wp_head’ priority 1.

    I don’t think the Twig templates touch the header, so you’ll need to detect the page template before Timber engages the Twig templates.

    Unfortunately, Twig and Timber are out of my areas of expertise. So, I can’t point you in the right direction on this part. I suggest reaching out to them, as they probably have a library available for altering SEO-plugin fields.

    Now, if you wish to implement ACF fields as parsable description excerpts, then I suggest using the filter below, where my-field should be changed to your respective field.

    add_filter( 'the_seo_framework_fetched_description_excerpt', function( $excerpt, $page_id ) {
    	$field = function_exists( 'get_field' ) ? get_field( 'my-field', $page_id ) : '';
    	return $field ?: $excerpt;
    }, 10, 2 );
    Thread Starter Jg

    (@adesignday)

    Hi Sybre,

    Many thanks for that info, ill give it a whirl, otherwise ill chase this up with twig and timber.

    Much apprieciated for your support.

    Regards
    Ads

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Site using Twig templates with Timber, title and description Fix’ is closed to new replies.