Define in PHP not accept space - php

I use define() function to make settings page for my site.
In my settings.php
define('DESCRIPTION', "Admin Dashboard Template");
define('TITLE', "Modern");
define('KEYWORDS', "admin,dashboard");
define('AUTHOR', "Minh Tan");
In my index.php
<?php include('config/settings.php'); ?>
<!DOCTYPE html>
<html>
<head>
<!-- Title -->
<title><?php echo TITLE; ?> | Login - Sign in</title>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<meta charset="UTF-8">
<meta name="description" content=<?php echo DESCRIPTION; ?> />
<meta name="keywords" content=<?php echo KEYWORDS; ?> />
<meta name="author" content=<?php echo AUTHOR; ?> />
But when i run on my browser. It make this results:
Help me! Thanks.

Wrap your PHP statements in double quotes.. they go missing after your charset.
<meta name="description" content="<?php echo DESCRIPTION; ?>" />
<meta name="keywords" content="<?php echo KEYWORDS; ?>" />
<meta name="author" content="<?php echo AUTHOR; ?>" />

Related

Facebook Open Graph Error - Inferred Property & Object Missing a Required Value

I understand there there are many questions regarding FB open graphs already asked on the forum. I have looked through pretty much evrything (multiple) times. I just dont get it why I continue to get the above errors when everything seems to be inline with what FB and others are saying.
here is what I have in the header.tpl
<!-- Facebook Meta Tags -->
<meta property="og:url" content="<?php echo $base; ?>/index.php?
route=product/product&product_id=<?php echo $product_id;?>" />
<meta property="og:type" content="website" />
<meta property="og:title" content="<?php echo
$product_heading_title; ?>" />
<meta property="og:description" content="<?php echo
$product_description; ?>" />
<meta property="og:image" content="<?php echo $product_thumb; ?>" />
<meta property="website:section" content="Product share offers" />
<meta property="website:published_time" content="<?php echo
strtotime('now'); ?>" />
<meta property="website:modified_time" content="<?php echo
strtotime('+30min'); ?>" />
<meta property="website:tag" content="Facebook" />
<meta property="website:tag" content="Products" />
<meta name="twitter:card" content="product">
<meta name="twitter:site" content="#publisher_handle">
<meta name="twitter:title" content="<?php echo $product_heading_title; ?
>">
<meta name="twitter:description" content="<?php echo
$product_description; ?>">
<meta name="twitter:creator" content="#author_handle">
<meta name="twitter:image" content="<?php echo $product_thumb; ?>">
<meta property="og:title" content="<?php echo
$product_heading_title; ?>" />
<meta property="og:description" content="<?php echo
$product_description; ?>" />
<meta property="og:image" content="<?php echo $product_thumb; ?>" />
<!-- Google+ Meta Tags -->
<link href="https://plus.google.com/" rel="publisher">
<meta itemprop="name" content="<?php echo $product_heading_title; ?
>">
<meta itemprop="description" content="<?php echo
$product_description; ?>">
<meta itemprop="image" content="<?php echo $product_thumb; ?>">
<?php
}
?>

Why does sharing page on Facebook does not show the image?

So, I have this article page which sometimes has post with image of 600x315 dimension and are mostly under 100kb.
Following are the meta I use on the article.php site, but when I share a post on Facebook the image section shows blank. What is that I am missing on these meta?
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="<?php echo $row['keyword']; ?>">
<meta name="description" content="<?php echo metadesc($row['description']); ?>">
<link rel="canonical" href="<?php echo $site_path.$url; ?>" />
<!-- for Facebook -->
<meta property="og:title" content="<?php echo ucletters($row['title']); echo ' | '; echo $site_name;?>" />
<meta property="og:type" content="article" />
<meta property="og:image" content="<?php echo $site_path.'uploads/images/'.$row['image']; ?>" />
<meta property="og:image:width" content="200" />
<meta property="og:image:height" content="200" />
<meta property="og:url" content="<?php echo $site_path.$url; ?>" />
<meta property="og:description" content="<?php echo metadesc($row['description']); ?>" />
<!-- for Twitter -->
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="<?php echo ucletters($row['title']); echo ' | '; echo $site_name;?>" />
<meta name="twitter:description" content="<?php echo metadesc($row['description']); ?>" />
<meta name="twitter:image" content="<?php echo $site_path.'uploads/images/'.$row['image']; ?>" />
Visit
Facebook developer debug tool
to check the issue with your url(s).Read their guidelines and that will surely work.Good luck

What is the best way to Include meta tags in the head section of a PHP template?

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 }?>

What do I need to add to this facebook og metadata?

I've got a share button that I am trying to modify to my specific needs. Here is the code.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:og="http://ogp.me/ns#"
xmlns:fb="http://www.facebook.com/2008/fbml">
<html>
<meta property="fb:app_id" content="lotsanumbers" />
<meta property="og:title" content="FOR SALE"/>
<meta property="og:type" content="product"/>
<meta property="og:url" content="http://www.website.com.au/php_test.php"/>
<meta property="og:image" content="http://www.website.com.au/ddfut14-1148.jpg"/>
<meta property="og:description" content="http://www.website.com.au/php_test.php<?php echo $title; ?>" />
Everything is working as requires except for the og:description. When I debug in facebook facebook is only seeing
<meta property="og:description" content="http://www.website.com.au/php_test.php
it is not scraping
<?php echo $title; ?>
from the same line what am I missing?
og:description is a tag that should contain text, you should be doing like:
<meta property="og:description" content="<?php echo $title; ?>" />
//where $title should be a defined variable that contains some text
or
<meta property="og:description" content="<?php echo file_get_contents("http://www.website.com.au/php_test.php"); ?>" />
//where your php_test.php file should echo out text

Execute php function in another part of code

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');

Categories