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

    (@cybr)

    Hi Julius,

    That’s possible, with a filter!

    I’ve made two versions, it’s up to you to decide which you’d like. Both are untested!

    Version 1: Compatibility filter. It’s heavier, but will prevent theme issues where the title is output later than the meta tags.

    add_filter( 'the_seo_framework_title_args', 'my_title_adjustments' );
    /**
     * Determine the title status.
     */
    function my_title_adjustments( $args = array() ) {
    
    	if ( isset( $args['meta'] ) && $args['meta'] ) {
    		//* Cache and adjust filter, only when outputting meta tags.
    		add_filter( 'the_seo_framework_add_blogname_to_title', 'my_title_blogname_cache' );
    		add_filter( 'the_seo_framework_add_blogname_to_title', '__return_false' );
    	} else {
    		//* Otherwise, reset the filter.
    		add_filter( 'the_seo_framework_add_blogname_to_title', 'my_title_blogname_cache' );
    	}
    
    	return $args;
    }
    
    /**
     * Caches the filter output.
     */
    function my_title_blogname_cache( $current = true ) {
    
    	static $cache = null;
    
    	if ( isset( $cache ) )
    		return $cache
    
    	return $cache = $current;
    }

    Version 2: Straight to the point. Is fast, uses less memory but does not consider theme/plugin compatibility:

    add_filter( 'the_seo_framework_title_args', 'my_title_adjustments' );
    /**
     * Determine the title status.
     */
    function my_title_adjustments( $args = array() ) {
    
    	static $has_run = null;
    
    	if ( isset( $has_run ) )
    		return $args;
    
    	if ( isset( $args['meta'] ) && $args['meta'] ) {
    		//* Adjust filter, only when outputting meta tags.
    		add_filter( 'the_seo_framework_add_blogname_to_title', '__return_false' );
    	}
    
    	$has_run = true;
    
    	return $args;
    }

    Take a close look at the og:title and twitter:title output to see what’s going into the Facebook/Twitter crawler.

    Please note that Facebook/Twitter might hold scrape data cache, so the title might not be updated directly when sharing.

    I hope this helps! Have a great day!

    Thread Starter Julius E

    (@julius-e)

    Thanks very much for the quick (and detailed!) response Sybre. I’ll try them both with a functionality plugin starting from the second one. Many thanks for your help.

    @cybr – Should this code example still work, or has it been deprecated? I tried it with no success.

    When I did a var_dump() of the $args array, $args[‘meta’] always returns false so the conditional filter does not run.

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi @daltonrooney,

    It’s a bug you’ve encountered that got the parameter bypassed unintentionally — it will be fixed in the next patch.
    The commit that fixes it was pushed 25 days ago.

    2.9.2 should be released this weekend, or shortly thereafter.

    Cheers!

    Great to know, thank you so much!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to share to social media without site name’ is closed to new replies.