Skip to content

Instantly share code, notes, and snippets.

View imelgrat's full-sized avatar

Iván Melgrati imelgrat

View GitHub Profile
@imelgrat
imelgrat / add_hatom_tags.php
Last active February 14, 2019 22:02
Adds hidden hatom tags to WordPress posts after the content block. They're not visible to humans but parsers will still see and parse them
<?php
/**
* Adds hidden hatom tags to WordPress posts after the content block.
* They're not visible to humans but parsers will still see and parse them.
*
* @link https://imelgrat.me/wordpress/hentry-fix-errors-wordpress/
*
* @param string The post content
*/
function add_hatom_tags($content)
@imelgrat
imelgrat / wordpress-hEntry-tags.php
Last active February 14, 2019 22:03
Simple example showing how add the required tags to a WordPress theme in order to comply with the Google Search Console hEntry specifications.
<?php
/**
* Adds hatom tags to WordPress posts after the post title.
* Fixes Google Search Console hEntry specification errors.
*
* @link https://imelgrat.me/wordpress/hentry-fix-errors-wordpress/
*/
?>
<h2 class="post-title">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
@imelgrat
imelgrat / remove-hentry.php
Last active December 22, 2021 18:43
Fixing the ‘Missing required hCard / hEntry’ Google Search Console errors (dirty fix)
<?php
function imelgrat_remove_hentry($class)
{
$class = array_diff($class, array('hentry'));
return $class;
}
add_filter('post_class', 'imelgrat_remove_hentry');
@imelgrat
imelgrat / check-youtube-video-oembed.php
Created February 14, 2019 21:28
The function fetches response headers from YouTube's oEmbed URL for a given video and crawls through thenm in order to find whether the video actually exists.
<?php
/**
* Find if a Youtube video exists.
*
* The function fetches response headers from YouTube's oEmbed URL for a given video
* and crawls through thenm in order to find whether the video actually exists.
*
* @link https://imelgrat.me/json-xml/oembed-protocol-embed-videos-news/
*
@imelgrat
imelgrat / oembed.json
Created February 14, 2019 21:18
Example of oEmbed content file (from Youtube)
{
"html": "<iframe width=\"480\" height=\"270\" src=\"https://www.youtube.com/embed/u8Kt7fRa2Wc?feature=oembed\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen></iframe>",
"width": 480,
"thumbnail_height": 360,
"provider_url": "https://www.youtube.com/",
"thumbnail_width": 480,
"version": "1.0",
"type": "video",
"title": "The Expert: Progress Meeting (Short Comedy Sketch)",
"height": 270,
<?php
/**
* Example of the IsValidISBN function.
*
* @link https://imelgrat.me/php/php-validate-barcode-numbers/
*/
// ISBN assigned to "PHP in a Nutshell" by Paul Hudson, 2005
echo 'Is ISBN "'.$code.'" valid? '. (BarcodeValidator::IsValidISBN('9780596100674') ? 'true' : 'false');
?>
@imelgrat
imelgrat / build.json
Created February 14, 2019 21:02
XCode 10 build upgrade makes Cordova builds fail. Make it work again
"ios": {
"release": {
"buildFlag": [
"-UseModernBuildSystem=0"
]
},
"debug": {
"buildFlag": [
"-UseModernBuildSystem=0"
]
@imelgrat
imelgrat / EmmAppConfig.js
Created February 14, 2019 20:54
AppConfig and Cordova: Getting EMM configuration data with the "Cordova Plugin for EMM App Config"
/**
* AppConfig and Cordova.
*
* Getting EMM configuration data with the "Cordova Plugin for EMM App Config".
* Callback for "deviceready" event.
*
* @link https://imelgrat.me/phonegap/appconfig-cordova-emm/
* @author Iván Melgrati.
*/
function onDeviceReady() {
@imelgrat
imelgrat / jquery-ajax-example.js
Last active February 14, 2019 19:59
jQuery AJAX call example
$.ajax(URL, {
success: function(data) {
// Do something with the returned data
},
error: function() {
//Handle error here
}
});
});
@imelgrat
imelgrat / check-youtube-id.php
Last active April 27, 2018 05:27
Verify whether a YouTube video exists using PHP and oEmbed status codes. Instead of actually fetching the video’s URL using a tool suchas a cURL, we can speed things up by just checking the response headers by using PHP’s get_headers() function. Full article: https://imelgrat.me/json-xml/oembed-protocol-embed-videos-news/
<?php
/**
* @author Ivan Melgrati
* @copyright 2018
*/
function YouTube_Check_ID($videoID)
{
$is_valid = true;