Dynamically adding meta tags using javascript or jquery [twitter cards]

送分小仙女□ 提交于 2019-12-01 07:54:59

You can't, at least not in any way that Twitter is going to recognise.

When Twitter fetches the page, it is always going to get the meta elements that are in the HTML, never ones added with client side JavaScript.

If you are changing content dynamically then make use of the history API to update the URI, and make sure that the server will generate all the content for each URI when the URI is used as an entry point (you can still use JavaScript to generate the content when moving from another page on the site).

You can generate pages dynamically (server side) as long as you don't intend to change them after. Think about the process in the same way you would build landing pages for SEO purposes. Twitterbot is in many ways really similar to Googlebot and similar indexers.

See https://dev.twitter.com/blog/twitter-cards-tips-tricks for a few examples of sites doing this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!