PHP library that helps rendering twitter embedded timelines
PHP 7.0+ - Only Composer installation supported
Run the command below to install via Composer
composer require mpalourdio/twitter-widgets
$widgetOptions = new WidgetOptions($options);
$userTimeline = new TimelineBuilder($widgetOptions);
echo $userTimeline->renderWidget();
$options
can handle these parameters : https://dev.twitter.com/web/embedded-timelines#options
Their PHP equivalent as array keys to use in the $options
array are :
'class' => 'A css class, by default it will be twitter-timeline',
'href' => 'The link to the timeline',
'hrefText' => 'A title for your timeline to display',
'dataWidgetId' => 'Your data widget ID : must be a string (!)',
'dataTheme' => 'ex: dark',
'dataLinkColor' => 'ex: #cc0000',
'width' => 300 (integer),
'height' => 400 (integer),
'dataChrome' => 'noheader nofooter noborders noscrollbar transparent', => a string with options separated by a single space
'dataBorderColor' => 'border color used by the widget',
'language' => 'The widget language detected from the page, based on the HTML lang attribute of your content. You can also set the HTML lang attribute on the embed code itself.',
'dataTweetLimit' => 20,
'dataRelated' => 'benward,endform',
'dataAriaPolite' => 'polite or assertive',
The TimelineBuilder#renderWidget() method accepts a boolean to disable the javascript code added to each widget. Useful if you have more that one widget to avoid JS overhead.
When disabled, to add only once the needed javascript to your HTML code, use OneTimeJsProvider#getOneTimeWidgetJs() just before your </body>
More information here : https://dev.twitter.com/web/javascript/loading
A ZF2 view helper is available here : https://github.com/mpalourdio/zf2-twitter-widget
A twig extension is available here : https://github.com/mpalourdio/TwitterWidgetBundle