WordPress.org

Ready to get started?Download WordPress

Forums

All in One SEO Pack
[resolved] Twitter card function request (18 posts)

  1. solosails
    Member
    Posted 4 months ago #

    Hi,

    Having delved into the twitter card stuff for the first time the other day I have a request that I'm sure you're planning on implementing anyway, but as a user I would like to say this would be very handy ...

    Is there any way to have an option in a post (and more importantly a product) that allows to select the type of twitter card to be used? Ie summary (which is is fixed to now) or summary_large_image or product etc?

    This would be a very handy and simple thing to add and would make this function a lot more useful.

    Yesterday I altered your code a little to make it default as the summary_large_image rather than summary, which for me is a better option to have as standard, but this will obviously get wiped by the next update and to have a choice for different situations would be great anyway.

    Thanks very much in advance.

    Cheers.

    https://wordpress.org/plugins/all-in-one-seo-pack/

  2. Peter Baylies
    Member
    Plugin Author

    Posted 4 months ago #

    Hi solosails,

    Thanks for the suggestion, I'll add it to the roadmap; you can currently do this with our hooks as well, here's a code example:

    add_filter( 'aiosp_opengraph_meta', 'solosails_filter_card', 10, 3 );
    
    function solosails_filter_card( $value, $type, $field ) {
        if ( ( $type == 'twitter' ) && ( $field == 'card' ) ) {
            $value = 'summary_large_image';
        }
        return $value;
    }
  3. solosails
    Member
    Posted 4 months ago #

    Hi Peter,

    Thanks for your reply and the code, I'll give it a go!

    Look forward to the updated version.

    Thanks again, Andrew

  4. solosails
    Member
    Posted 4 months ago #

    Works a treat, thanks again.

  5. Peter Baylies
    Member
    Plugin Author

    Posted 4 months ago #

    You're welcome Andrew, always glad to hear that!

  6. solosails
    Member
    Posted 4 months ago #

    Ah, actually, I found an issue using this, it not your plugin though.

    Today, I installed woocommerce twitter card product plugin which changes your titter card meta to product on the product pages. This worked fine, but now I use your hook, it doesn't do this any more?

    Any ideas?

  7. Peter Baylies
    Member
    Plugin Author

    Posted 4 months ago #

    Hi Andrew,

    I don't know how they go about changing it, but one solution would be to check for their product pages in this function and not change the value in that case (or change it to product in this code as well).

    function solosails_filter_card( $value, $type, $field ) {
        if ( ( $type == 'twitter' ) && ( $field == 'card' ) ) {
            if ( ( function_exists( 'is_product' ) ) && ( is_product() ) ) {
                $value = 'product';
            } else {
                $value = 'summary_large_image';
            }
        }
        return $value;
    }
  8. solosails
    Member
    Posted 4 months ago #

    hmm, works correctly in product pages, but the 'else summary_large_image' doesn't seem to appear in the other pages, just stays as summary?

  9. Peter Baylies
    Member
    Plugin Author

    Posted 4 months ago #

    That's strange; see if it does the same thing without the WooCommerce Twitter Card product plugin active.

  10. solosails
    Member
    Posted 4 months ago #

    Nope, even with it deactivated, it doesn't show the large image on an ordinary post?

  11. Peter Baylies
    Member
    Plugin Author

    Posted 4 months ago #

    But is it outputting summary_large_image for the Twitter card meta? I trust you didn't get rid of the add_filter() line?

  12. solosails
    Member
    Posted 4 months ago #

    oops,,, yes I did delete it!

    I can confirm that your code works perfectly now, thank you very very much for your time, Andrew

    This works fine..

    add_filter( 'aiosp_opengraph_meta', 'solosails_filter_card', 10, 3 );
    function solosails_filter_card( $value, $type, $field ) {
        if ( ( $type == 'twitter' ) && ( $field == 'card' ) ) {
            if ( ( function_exists( 'is_product' ) ) && ( is_product() ) ) {
                $value = 'product';
            } else {
                $value = 'summary_large_image';
            }
        }
        return $value;
    }

    For anyone reading this, the plugin I am using in conjunction is Twitter Product Card for WooCommerce

  13. solosails
    Member
    Posted 4 months ago #

    Hi again Peter,

    This is just pushing my luck a bit... well a lot actually!

    Any ideas how I might get AIOSEOP to add the 'player' twitter card into posts?

    It requires

    <meta name="twitter:card" content="player"> as a minimum and
    <meta name="twitter:player:stream" content="http://your-site.com/streaming-file.mp4"> for full functionality.

    Just hoped you might go, yeah, just add xxx in your functions php... perhaps!

    Thanks, Andrew

  14. solosails
    Member
    Posted 2 months ago #

    Hey Peter,

    Thanks ever so much for the recent release of AIO SEO that includes the Twitter Card Meta options.

    Is there any chance in the next release you could put an option in the AIO SEO settings to choose what the default is?

    I pretty much always want to use the 'Summary Large Image' , but currently it defaults to 'Summary' which is fine, but means I have to remember every time to change that setting.

    Many thanks for all your help again, Andrew

  15. solosails
    Member
    Posted 2 months ago #

    Perhaps, for now, is there a hack I can implement in the AIO SEO functions that will make the default into Summary Large Image?

  16. solosails
    Member
    Posted 2 months ago #

    Hi,

    My apologies, you have done this already, sorry I missed that the first time I looked in the settings!

    Great work, thanks again!

    Cheers, Andrew

  17. Peter Baylies
    Member
    Plugin Author

    Posted 2 months ago #

    No problem, glad it's working for you. :)

  18. solosails
    Member
    Posted 2 months ago #

    Very well indeed, thanks again

Reply

You must log in to post.

About this Plugin

About this Topic