I am being facing this problem since the last 8 hours, my nose is almost on the keyboard...
I started searching for a solution to put a code on the header.php of my Wordpress for facebook og:image.
It seems simple BUT the page always stop loading when reaching the line of code so it is always a white page without any information.
Page stops loading when reaches <?php echo get_fbimage(); ?> - No solution
Here is the line: <meta property="og:image" content="<?php echo get_fbimage(); ?>"/>
1- If I remove that line or the <?php echo get_fbimage(); ?>, everything goes well...
2- Even without the function get_fbimage() on functions.php, it doesn't work.
Here is the page online: http://www.contagiarte.pt/centroformacaocultural/formacao/formacao-fixa/yoga/
I need to get a solution to fix this or alternative solution for getting Facebook pulling the correct image of each wordpress page.
Thank's in advance.
Here goes the first part of header.php code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:og="http://opengraphprotocol.org/schema/"
xmlns:fb="http://www.facebook.com/2008/fbml" <?php language_attributes(); ?>>
<head profile="http://gmpg.org/xfn/11">
<title><?php if (is_home()) { ?><?php bloginfo('name'); ?> - <?php bloginfo('description'); ?><?php } else { ?><?php wp_title($sep = ''); ?> - <?php bloginfo('name'); ?><?php } ?></title>
<meta http-equiv="content-type" content="<?php bloginfo('html_type') ?>; charset=<?php bloginfo('charset') ?>" />
<!-- Facebook Open Graph -->
<meta property="fb:app_id" content="155171734506350" />
<meta property="og:title" content="<?php the_title(); ?>"/>
<meta property="og:description" content="<?php
if ( function_exists('wpseo_get_value') ) {
echo wpseo_get_value('metadesc');
} else {
echo $post->post_excerpt;
}
?>"/>
<meta property="og:url" content="<?php the_permalink(); ?>"/>
<meta property="og:type" content="<?php
if (is_single() || is_page()) { echo "article"; } else { echo "website";}
?>"/>
<meta property="og:site_name" content="<?php bloginfo('name'); ?>"/>
<meta property="og:image" content="<?php echo get_fbimage(); ?>"/>
<meta name="description" content="<?php bloginfo('description') ?>" />
<?php if(is_search()) { ?>
<meta name="robots" content="noindex, nofollow" />
<?php }?>
Maybe it’s because the page is not loading the functions.php that you mention?
So maybe change this:
<?php echo get_fbimage(); ?>
To this this:
<?php echo require_once('functions.php'); get_fbimage(); ?>
I am assuming that the functions.php is in the same folder as this page? If not then you need to set that require_once to point to the location of functions.php
Related
How can i remove the <meta http-equiv="content-type" content="text/html; charset=utf-8" />
on this PHP Joomla Template? Because I have a Duplication of the Meta Tag from Joomla and from the Template :/ The Head.php file it is calling is:
<meta charset="<?php echo $this['system']->document->getCharset(); ?>">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<?php if($this['config']->get('responsive', true)): ?>
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php endif; ?>
<?php if (isset($error)): ?>
<title><?php echo $error; ?> - <?php echo $title; ?></title>
<?php else: ?>
<jdoc:include type="head" />
<?php endif; ?>
and the Index.php is:
// get theme configuration
include($this['path']->path('layouts:theme.config.php'));
?>
<!DOCTYPE HTML>
<html lang="<?php echo $this['config']->get('language'); ?>" dir="<?php echo $this['config']->get('direction'); ?>" data-config='<?php echo $this['config']->get('body_config','{}'); ?>'>
<head>
<?php echo $this['template']->render('head'); ?>
</head>
<body class="<?php echo $this['config']->get('body_classes'); ?>">
here is an Image of this Problem:
Link to the Problem ( imgur )
If i understand your problem right. Do you want to remove the duplicate chartset?
Simple remove the first line in your first code sample.
And you can try $doc->setHtml5(true);in the index.php
I have some problems when I share a wordpress post on telegram. meta tags are not displaying on true way. but in page view source it get true data. I don't know what's the problem. I write the follow code in header.php file.
<?php global $post; ?>
<meta property="og:title" content="<?php
if(is_front_page()){
echo get_bloginfo();
}
else
echo the_title();
?>"/>
<meta property="og:description" content="<?php echo "eda website" ; ?>"/>
<meta property="og:type" content="article"/>
<meta property="og:url" content="<?php
if(is_front_page())
echo "http://eda-af.com";
else
echo the_permalink();
?>"/>
<meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/>
<meta property="og:image" content="<?php
if(is_front_page())
echo "http://eda-af.com/wp-content/themes/mytheme/img/meta_logo.jpg";
else
$img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'medium');
echo $img_src[0];
?>"/>
I find the answer!
the problem was because telegram keeps link's cache.
so I used the google site for shorten my url (goo.gl) and also with telegram bot (#webpagebot).
the problem solved.
I created a simple php template.
In the header.php I have the following lines of code:
<!DOCTYPE HTML>
<html lang="en"><head>
<meta charset="utf-8">
<title><?php echo $title ?></title>
<meta name="description" content="<?php echo $description ?>">
<link rel="canonical" href="<?php echo $canonical ?>">
</head><body>
here rest of code (header, menu etc...)
On all pages I have the following lines of code at the top:
<?php
$title="";
$description="";
$canonical="";
$page_schema="http://schema.org/WebPage";
$INC_DIR = $_SERVER["DOCUMENT_ROOT"]. "/includes/";
require($INC_DIR. "header.php"); ?>
I have pages with Open Graph meta tags and some pages who don't have Open Graph meta tags.
I have pages with
<link rel="alternate" hreflang="nl" href="">
and pages that don't use this.
I have 2 pages with robots meta tag noindex follow and many pages who don't use any robots meta tag.
Now i'm using the following option:
I've added the following line in the header.php
<?php echo $meta_tags ?>
Example:
<!DOCTYPE HTML>
<html lang="en"><head>
<meta charset="utf-8">
<title><?php echo $title ?></title>
<meta name="description" content="<?php echo $description ?>">
<link rel="canonical" href="<?php echo $canonical ?>">
<?php echo $meta_tags ?>
And the following lines on pages (not all use hreflang tag):
$meta_tags='<link rel="alternate" hreflang="nl" href="">
<meta property="og:image" content="">
<meta property="og:title" content="">
<meta property="og:description" content="">
<meta property="og:url" content="">';
Example:
<?php
$title="";
$description="";
$canonical="";
$meta_tags='<link rel="alternate" hreflang="nl" href="">
<meta property="og:image" content="">
<meta property="og:title" content="">
<meta property="og:description" content="">
<meta property="og:url" content="">';
$page_schema="http://schema.org/WebPage";
$INC_DIR = $_SERVER["DOCUMENT_ROOT"]. "/includes/";
require($INC_DIR. "header.php"); ?>
Is this a good solution to include some meta tags on pages that do use them? Or is there a better way?
Like adding NULL (without quotes) to empty variables like: $title=NULL;
Example (for a few pages that don't use opengraph):
header.php:
<meta property="og:title" content="<?php echo $og_title ?>">
<meta property="og:description" content="<?php echo $og_description ?>">
<meta property="og:url" content="<?php echo $og_url ?>">';
on pages (which don't use open graph tags):
$og_title=NULL;
$og_description=NULL;
$og_url=NULL;
What is the best solution? Is there a better solution?
Btw... I was following the steps of this tutorial here: http://www.heliomedia.com/tutorials/html5-template-with-seo-friendly-variables/
Yes, omit the variables you're not using in each page. In your head include, wrap each meta tag in a check to see if it's used, e.g.:
<?php if (isset($og_title)) {?>
<meta property="og:title" content="<?php echo htmlspecialchars($og_title);?>">
<?php }?>
I tried different ways to get my value data in a custom field and put it in the meta tags property in header but no luck.
My site is running based on Wordpress. I created a page to show data from my custom fields. I added a facebook share button to share the content on Facebook.
When I clicked on share button, Facebook only catched Wordpress Meta Tags default meta tags.
I edited open-graph.php, added a condition to make Wordpress to use my custom meta tags only on that page.
The issue is, I cannot or I don't know how to get the data from database and put it in the meta tags. Because the header is loaded before the body, so those meta tags in header are always loaded before the function getting data from database returns the value. Even when I create the tag I need, they are still located in the body, which is not a correct position for Meta tags.
I tried to put my data function directly in the open-graph.php, right below my page condition statement, but it still doesn't work.
Is there anyway to get the data loaded from body and put it in meta tags in header? please help.
I've set up the og meta tags recently in my header.php file in this manner:
<?php
$theme = wp_get_theme();
$screenshot_url = esc_url( $theme->get_screenshot() );
?>
<?php if ( is_home() ): ?>
<meta property="og:url" content="<?php echo get_home_url(''); ?>" />
<meta property="og:type" content="website" />
<meta property="og:title" content="<?php echo get_bloginfo('name'); ?>" />
<meta property="og:description" content="<?php echo get_bloginfo('description'); ?>" />
<meta property="og:image" content="<?php echo $screenshot_url; ?>" />
<?php elseif( is_category() ):
$cat_id = get_query_var('cat');
$cat_name = get_cat_name($cat_id);
$cat_desc = (category_description( $cat_id ) != '') ? category_description( $cat_id ) : get_bloginfo('description');
?>
<meta property="og:url" content="<?php echo get_category_link($cat_id); ?>" />
<meta property="og:type" content="website" />
<meta property="og:title" content="<?php echo $cat_name; ?>" />
<meta property="og:description" content="<?php echo $cat_desc; ?>" />
<meta property="og:image" content="<?php echo $screenshot_url; ?>" />
<?php else: ?>
<meta property="og:url" content="<?php the_permalink(); ?>" />
<meta property="og:type" content="website" />
<meta property="og:title" content="<?php echo get_the_title(); ?>" />
<meta property="og:description" content="<?php echo get_the_excerpt(); ?>" />
<?php if(has_post_thumbnail()):
$url = wp_get_attachment_url( get_post_thumbnail_id() );
?>
<meta property="og:image" content="<?php echo $url; ?>" />
<?php else: ?>
<meta property="og:image" content="<?php echo $screenshot_url; ?>" />
<?php endif; ?>
<?php endif; ?>
You can add any conditional you need - for instance to check if you're on a single page, or some certain template.
When I use facebook share button I get correct image and info.
Hope this helps :)
i have a wordpress based website.
I have a standard wordpress loop that executes at the start in the <body> part of the html. Now, i would like to print out the og tags in the head, but the data needed for those tags (title, description,...) is available to me after the <head> part when i do the loop.
Is there a way to solve this in php without me having to move my code to the beggining of the head tag (or somewhere before)?
If your problem is settiing meta tags, this works for me and is also useful because it checks if you are viewing a post or the website
<?php if (is_single() || is_author()) { ?>
<meta property="og:site_name" content="<?php bloginfo('name'); ?>" />
<meta property="og:url" content="<?php the_permalink() ?>"/>
<meta property="og:title" content="<?php wp_title(); ?>" />
<meta property="og:description" content="<?php echo strip_tags(get_bloginfo('description')); ?>" />
<meta property="og:type" content="article" />
<meta property="og:image" content="<?php if (function_exists('wp_get_attachment_thumb_url')) {echo wp_get_attachment_thumb_url(get_post_thumbnail_id($post->ID)); }?>" />
<?php } else { ?>
<meta property="og:site_name" content="<?php bloginfo('name'); ?>" />
<meta property="og:url" content="<?php the_permalink() ?>"/>
<meta property="og:title" content="<?php wp_title(); ?>" />
<meta property="og:description" content="<?php bloginfo('description'); ?>" />
<meta property="og:type" content="website" />
<?php } ?>
Install a hook for wp_head action.
function modify_head()
{
?>
<meta property="og:site_name" content="<?php bloginfo('name'); ?>" />
<?php
}
add_action('wp_head', 'modify_head');