I used seo validator to check my website, but it says my website does not have site title. I have these header codes below:
<head profile="http://gmpg.org/xfn/11">
<meta name="google-site-verification" content="RR4KnVDyxKEeBxQg8Qwphb0E2RuBTxVE3y-NrLS_tsw" />
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<title><?php bloginfo('name'); ?> <?php if ( is_single() ) { ?> » <?php } ?> <?php wp_title(); ?></title>
<meta name="Description" content="Davao Property For Sale is the desired partner of Filipino families in finding and owning a HOME in Davao City, Philippines every step of the way." />
<meta name="Keywords" content="Davao City, real estate, House for sale, rush house, brand new, ready for occupancy, Davao Property" />
Please help!
Try this:
<title>
<?php
$title = bloginfo('name');
if ( is_single() ) {
$title .= '»';
}
$title .= wp_title();
echo $title;
?>
</title>
The idea is to use the variable $title to concatenate your title and finally write it with function echo.
<title><?php echo bloginfo('name').(is_single()?' »':'').' '.wp_title() ?></title>
or
<title><?= bloginfo('name').(is_single()?' »':'').' '.wp_title() ?></title>
or
<?php $pageT = bloginfo('name');
if (is_single()) $pageT .= ' »';
$pageT .= ' ' . wp_title(); ?>
<title><?php echo $pageT ?></title>
There are some other possibilities to write this, though.
Related
in order to have the right image and the right link everytime I share on Facebook, here's what i've done on my Wordpress/Woocommerce header:
<meta property="og:image" content="<?php the_post_thumbnail_url(); ?>" />
<meta property="og:title" content="<?php echo the_title(); ?> by Pixel Komando" />
<meta property="og:url" content="<?php echo get_permalink(); ?>" />
Everything works fine in my woocommerce products pages, but when i want to share the Shop Page, the FB debugger shows me this :
URL : https://www.pixelkomando.com/shop
Meta tag og:url https://www.pixelkomando.com/shop/CATEGORY/PRODUCT/
It seems it works correctly everywhere except on the Shop Page itself. Instead of retrieving the Shop Page URL, it gives the URL of a random product.
I dont really know what is wrong.
Regards
Fero
As it is an archive page so whenever you call get_permalink() it will pick either the last or the first product URL, so what I'll suggest you to remove your code from header.php and add the following code in your functions.php
function wh_doctype_opengraph($output) {
return $output . '
xmlns:og="http://opengraphprotocol.org/schema/"
xmlns:fb="http://www.facebook.com/2008/fbml"';
}
add_filter('language_attributes', 'wh_doctype_opengraph');
function wh_fb_opengraph()
{
global $post;
if (is_home() && is_front_page())
{
?>
<meta property="og:type" content="website" />
<meta property="og:title" content="<?= get_bloginfo('name') ?>"/>
<meta property="og:url" content="<?= get_site_url() ?>"/>
<meta property="og:image" content="<?= get_site_url() . '/wp-content/uploads/myhome.jpg' ?>"/> <!-- replace it with your static image-->
<?php
}
//for singles post page
else if (is_single() && !is_product())
{
if (has_post_thumbnail($post->ID))
{
$img_src = wp_get_attachment_url(get_post_thumbnail_id($post->ID), 'medium');
}
//if featured image not present
else
{
$img_src = get_site_url() . '/wp-content/uploads/post.jpg'; //replace it with your static image
}
?>
<meta property="og:type" content="article" />
<meta property="og:title" content="<?= get_the_title($post->ID); ?>"/>
<meta property="og:url" content="<?= get_the_permalink($post->ID); ?>"/>
<meta property="og:image" content="<?= $img_src; ?>"/>
<?php
}
//for singles product page only
elseif (is_product())
{
$img_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'woocommerce_single_image_width'); //replace it with your desired size
?>
<meta property="og:type" content="product" />
<meta property="og:title" content="<?= get_the_title($post->ID); ?> by Pixel Komando"/>
<meta property="og:url" content="<?= get_the_permalink($post->ID); ?>" />
<meta property="og:image" content="<?= $img_url[0]; ?>"/>
<?php
}
//for product cat page
else if (is_product_category())
{
$term = get_queried_object();
$img_src = wp_get_attachment_url(get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true));
if (empty($img_src))
{
$img_src = get_site_url() . '/wp-content/uploads/myproductcat.jpg'; //replace it with your static image
}
?>
<meta property="og:type" content="object" />
<meta property="og:title" content="<?= $term->name; ?>" />
<meta property="og:url" content="<?= get_term_link($term->term_id, 'product_cat'); ?>" />
<meta property="og:image" content="<?= $img_src; ?>" />
<?php
}
//for shop page
elseif (is_shop())
{
?>
<meta property="og:title" content="<?= $term->name; ?>" />
<meta property="og:url" content="<?= get_permalink(woocommerce_get_page_id('shop')); ?>" />
<meta property="og:image" content="<?= get_site_url(); ?>/wp-content/uploads/myshop.jpg" /> <!-- replace it with your static image-->
<?php
}
else
{
return;
}
}
add_action('wp_head', 'wh_fb_opengraph', 5);
Code is tested and works.
Hope this helps!
It seems like the issue is with your og:url tag. Each time I re-scrape with the sharing debugger it is different. To me, this suggests the get_permalink() method is not returning a consistent result.
FYI, the og:url meta tag is not required, so an easy fix here is just to leave it off. You only really need it if you have multiple URLs to access the same resource and you want to let FB's crawler which is URL is the canonical one.
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 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 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
How can I add a different title, keyword and description in every page's <head> of my simple php website dynamically?
I have included file header.php in all of my pages, how can i know in what page the user in?
For example, I have php files register.php, and login.php, and I need different titles, keywords and descriptions.
I do not want use the $_GET method.
Thanks!
Set variables at the top of each page that will be read by header.php. Then insert the values of the variables in the right places in header.php. Here is an example:
register.php:
<?php
$title = "Registration";
$keywords = "Register, login";
$description = "Page for user registration";
include('header.php');
?>
header.php
<html>
<head>
<meta name="keywords" content="<?php echo $keywords; ?>" />
<meta name="description" content="<?php echo $description; ?>" />
<title><?php echo $title; ?></title>
</head>
<body>
Put the output inside a function (within your header.php) and insert its parameters at appropriate places into the markup.
function html_header($title = "Default") {
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title><?php echo $title ?></title>
</head>
…
<?php
}
you can try this:
for example the $page variable is your page name:
<?php
switch($page)
{
case 'home':
$title = 'title';
$keyword = 'some keywords..';
$desc = 'description';
break;
case 'download':
$title = 'title';
$keyword = 'some keywords..';
$desc = 'description';
break;
case 'contact':
$title = 'title';
$keyword = 'some keywords..';
$desc = 'description';
break;
}
if(isset($title))
{
?>
<title><?php echo $title; ?></title>
<meta name="keywords" content="<?php echo $keyword; ?>" />
<meta name="description" content="<?php echo $desc; ?>" />
<?php
}
else
{
?>
<title>default</title>
<meta name="keywords" content="default" />
<meta name="description" content="default" />
<?php
}
?>