{"id":1012,"date":"2016-07-06T18:04:38","date_gmt":"2016-07-07T00:04:38","guid":{"rendered":"https:\/\/emanuelpaxtian.com\/blog\/?p=1012"},"modified":"2016-07-06T18:13:30","modified_gmt":"2016-07-07T00:13:30","slug":"agregar-facebook-open-graph-y-twitter-cards-en-tu-sitio-wordpress-sin-plugins","status":"publish","type":"post","link":"https:\/\/emanuelpaxtian.com\/blog\/agregar-facebook-open-graph-y-twitter-cards-en-tu-sitio-wordpress-sin-plugins\/","title":{"rendered":"Agregar Facebook Open Graph y Twitter Cards en tu sitio WordPress sin Plugins"},"content":{"rendered":"<p>Agregar Facebook Open Graph y Twitter Cards en tu sitio WordPress es algo que sin duda tendras que hacer tarde o temprano, como lo he comentado el uso de plugins no me es del todo de mi agrado y por lo tanto les voy a dejar una forma de agregar <strong>Facebook Open Graph<\/strong> y <strong>Twitter Cards<\/strong>  sin el uso de ning\u00fan extra.<\/p>\n<p>Todo lo que tenemos que haces es abrir nuestro el administrador y editar nuestro archivo <strong> functions.php <\/strong>de nuestro tema y realizar los cambios en necesarios para su sitio les puedo listar los siguientes.<\/p>\n<ul>\n<li>og:site_name:<\/li>\n<li>twitter:card<\/li>\n<li>twitter:creator<\/li>\n<li>twitter:site<\/li>\n<\/ul>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction insertar_opengraph_doctype( $output ) {\r\n        return $output . ' xmlns:og=&quot;http:\/\/opengraphprotocol.org\/schema\/&quot; xmlns:fb=&quot;http:\/\/www.facebook.com\/2008\/fbml&quot;';\r\n\r\n\r\n    }\r\nadd_filter('language_attributes', 'insertar_opengraph_doctype');\r\n\r\n\/\/Lets add Open Graph Meta Info\r\n\r\nfunction insertar_meta() {\r\n    global $post;\r\n    if ( !is_singular()) \/\/if it is not a post or a page\r\n        return;\r\n \r\nif (is_single() || is_page() ) : if (have_posts() ) : while (have_posts() ) : the_post(); \r\n        echo '&lt;meta property=&quot;og:description&quot; content=&quot;'.get_the_excerpt().'&quot;&gt;';\r\n        echo '&lt;meta name=&quot;twitter:description&quot; content=&quot;'.get_the_excerpt().'&quot; \/&gt;';\r\n        endwhile; endif; elseif (is_home() ): \r\n        echo '&lt;meta property=&quot;og:description&quot; content=&quot;Sitio web personal donde trato temas de tecnologia en general y pragramaci\u00f3n principalmente php, mysql,css y jquery &quot;&gt;';\r\n        endif;\r\n        echo '&lt;meta property=&quot;fb:admins&quot; content=&quot;532138163535147&quot;\/&gt;';\r\n\r\n        echo '&lt;meta property=&quot;og:title&quot; content=&quot;' .get_the_title(). '&quot;\/&gt; ';\r\n\r\n        echo '&lt;meta property=&quot;og:type&quot; content=&quot;article&quot;\/&gt; ';\r\n\r\n        echo '&lt;meta property=&quot;og:url&quot; content=&quot;' . get_permalink() . '&quot;\/&gt; ';\r\n\r\n        echo '&lt;meta property=&quot;og:site_name&quot; content=&quot;Emanuel Paxtian&quot;\/&gt; ';\r\n\r\n        echo '&lt;meta name=&quot;twitter:card&quot; content=&quot;summary_large_image&quot; \/&gt;';\r\n\r\necho '&lt;meta name=&quot;twitter:title&quot; content=&quot;'.get_the_title().'&quot; \/&gt;';\r\necho '&lt;meta name=&quot;twitter:site&quot; content=&quot;@psolucionesnet&quot; \/&gt;';\r\n\r\necho '&lt;meta name=&quot;twitter:creator&quot; content=&quot;@psolucionesnet&quot; \/&gt;';\r\n       \r\n\r\n    if(!has_post_thumbnail( $post-&gt;ID )) { \r\n        $default_image=&quot;https:\/\/emanuelpaxtian.com\/blog\/avatar.jpg&quot;;\r\n        echo '&lt;meta property=&quot;og:image&quot; content=&quot;' . $default_image . '&quot;\/&gt; ';\r\n    }\r\n    else{\r\n        $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post-&gt;ID ), 'large' );\r\n        echo '&lt;meta property=&quot;og:image&quot; content=&quot;' . esc_attr( $thumbnail_src&#x5B;0] ) . '&quot;\/&gt; ';\r\n        echo '&lt;meta name=&quot;twitter:image&quot; content=&quot;' . esc_attr( $thumbnail_src&#x5B;0] ). '&quot; \/&gt;';\r\n    }\r\n    echo &quot;\r\n&quot;;\r\n}\r\nadd_action( 'wp_head', 'insertar_meta', 5 );\r\n<\/pre>\n<p>Espero te haya gustado este articulo y espero que lo usen y lo modifiquen ya que es un ejemplo b\u00e1sico pero se puede mejorar.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Agregar Facebook Open Graph y Twitter Cards en tu sitio WordPress es algo que sin duda tendras que hacer tarde o temprano, como lo he comentado el uso de plugins&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1013,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,21],"tags":[],"class_list":["post-1012","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-seo","category-wordpress"],"_links":{"self":[{"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/posts\/1012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/comments?post=1012"}],"version-history":[{"count":0,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/posts\/1012\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/media\/1013"}],"wp:attachment":[{"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/media?parent=1012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/categories?post=1012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/tags?post=1012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}