How to make if / else if into an array? - php

I have to add noindex to some url's, this is my code at the moment:
<?php if ($metanoindex) { ?>
<meta name="robots" content="noindex,follow" />
<?php } elseif ($_SERVER['REQUEST_URI']=='/dolls/1/bestselling' ) { ?>
<meta name="robots" content="noindex,follow" />
<?php } elseif ($_SERVER['REQUEST_URI']=='/dolls/1/bestselling/30' ) { ?>
<meta name="robots" content="noindex,follow" />
<?php } elseif ($_SERVER['REQUEST_URI']=='/dolls/1' ) { ?>
<meta name="robots" content="noindex,follow" />
<?php } else { ?>
<meta name="robots" content="index,follow" />
<?php } ?>
I wondered if there is a way to make an array of urls instead of repeating "else if" each time.

Try as below
<?php
$arr = array('/dolls/1/bestselling','/dolls/1/bestselling/30','/dolls/1');
if($metanoindex || in_array($_SERVER['REQUEST_URI'],$arr)){ ?>
<meta name="robots" content="noindex,follow" />
<?php
}
else {
?>
<meta name="robots" content="index,follow" />
<?php } ?>
PHP Manual: in_array()

$urls = array('/dolls/1/bestselling', '/dolls/1/bestselling/30', '/dolls/1');
if (in_array($_SERVER['REQUEST_URI'], $urls)) {
// Insert meta tag here
}

Related

Use BLOB image from MySQL db for meta og:image to show preview image to facebook

I can get a BLOB image from my MySQL database but I want to show it as a preview image when I post to facebook. I don't want to save the image to my computer because I will end up with too many images. The closest I can get is showing a load of ascii code instead of the actual image. Is it even possible to achieve this? This is the code I have at the moment.
<?php
require_once($_SERVER['DOCUMENT_ROOT']."/includes/config.php");
$keys = htmlspecialchars($_GET['id']);
$query = "SELECT * FROM birdtabletop WHERE id='$keys' AND approvalMsg = 'Approved' LIMIT 1";
if(!isset($error)){
try {
foreach ($db->query($query) as $row) {
//set vars here
$tTitle = $row['tabletop_name'];
$tPicture = $row['tabletop_photo'];
}
} catch(PDOException $e) {
header('Location: login.php');
}
}
if(!isset($row)){
header('Location: login.php');
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<?php include_once("includes/analyticstracking.php") ?>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><?php echo $tTitle; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="">
<meta property="og:title" content="<?php echo $tTitle; ?>">
<meta property="og:type" content="website">
<meta property="og:url" content="https://www.finchkeeper.com/viewtabletop.php<?php echo "
?id=".htmlspecialchars(filter_input(INPUT_GET, 'id')); ?>">
<?php
if($tPicture != NULL){
echo '<meta property="og:image" content="data:image/jpeg;base64,'.base64_encode( $tPicture ).'"/>';
}else{
echo '<meta property="og:image" content="https://www.finchkeeper.com/images/tabletop.jpg">';
}
?>
<meta property="og:description" content="" />

How can I remove the <meta http-equiv="content-type" content="text/html; charset=utf-8" /> of Joomla?

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

Error: Stray end tag head

I am tired to resolve the issue of Stray end tag head.
<!doctype html>
<html <?php language_attributes(); ?> >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="X-FRAME-OPTIONS" content="ALLOW-FROM" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>
<?php wp_title("|",true, 'right'); ?>
<?php if (!defined('WPSEO_VERSION')) { bloginfo('name'); } ?>
</title>
<link rel='shortcut icon' href='<?php echo get_template_directory_uri(); ?>/img/favicon.ico' type='image/x-icon' />
<?php
$page_amp_url = get_post_meta(get_the_ID(), 'amp_page_url', TRUE);
if(!empty($page_amp_url)){
echo'<link rel="amphtml" href="'.$page_amp_url.'" />';
}
?>
<?php $options = get_option('salient'); ?>
<?php if(!empty($options['responsive']) && $options['responsive'] == 1) { ?>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
<?php } else { ?>
<meta name="viewport" content="width=1200" />
<?php } ?>
<!--Shortcut icon-->
<?php if(!empty($options['favicon'])) { ?>
<link rel="shortcut icon" href="<?php echo nectar_options_img($options['favicon']); ?>" />
<?php } ?>
<?php if(is_page('5584')){ ?>
<meta property="og:image" content="https://www.accudock.com/wp-content/uploads/2016/11/willy-375x376-375x376.jpg" />
<meta property="og:image:width" content="375" />
<meta property="og:image:height" content="376" />
<meta property="og:image" content="https://www.accudock.com/wp-content/uploads/2016/11/willy1-375x376.jpg" />
<meta property="og:image:width" content="375" />
<meta property="og:image:height" content="376" />
<meta property="og:image" content="https://www.accudock.com/wp-content/uploads/2016/11/Untitled-1-375x376.jpg" />
<meta property="og:image:width" content="375" />
<meta property="og:image:height" content="376" />
<meta property="og:image" content="https://www.accudock.com/wp-content/uploads/2016/11/4x20-floating-dock-375x376.jpg" />
<meta property="og:image:width" content="375" />
<meta property="og:image:height" content="376" />
<?php }?>
<?php wp_head(); ?>
<?php
global $post;
global $woocommerce;
//check if parallax nectar slider is being used
$parallax_nectar_slider = using_nectar_slider();
$force_effect = get_post_meta($post->ID, '_force_transparent_header', true);
// header transparent option
$transparency_markup = null;
$activate_transparency = null;
$using_fw_slider = using_nectar_slider();
$using_fw_slider = (!empty($options['transparent-header']) && $options['transparent-header'] == '1') ? $using_fw_slider : 0;
if($force_effect == 'on') $using_fw_slider = '1';
$disable_effect = get_post_meta($post->ID, '_disable_transparent_header', true);
if(!empty($options['transparent-header']) && $options['transparent-header'] == '1') {
$starting_color = (empty($options['header-starting-color'])) ? '#ffffff' : $options['header-starting-color'];
$activate_transparency = using_page_header($post->ID);
$remove_border = (!empty($options['header-remove-border']) && $options['header-remove-border'] == '1') ? 'true' : 'false';
$transparency_markup = ($activate_transparency == 'true') ? 'data-transparent-header="true" data-remove-border="'.$remove_border.'" class="transparent"' : null ;
}
//header vars
$logo_class = (!empty($options['use-logo']) && $options['use-logo'] == '1') ? null : 'class="no-image"';
$sideWidgetArea = (!empty($options['header-slide-out-widget-area'])) ? $options['header-slide-out-widget-area'] : 'off';
$sideWidgetClass = (!empty($options['header-slide-out-widget-area-style'])) ? $options['header-slide-out-widget-area-style'] : 'slide-out-from-right';
$fullWidthHeader = (!empty($options['header-fullwidth']) && $options['header-fullwidth'] == '1') ? 'true' : 'false';
$headerSearch = (!empty($options['header-disable-search']) && $options['header-disable-search'] == '1') ? 'false' : 'true';
$headerFormat = (!empty($options['header_format'])) ? $options['header_format'] : 'default';
$mobile_fixed = (!empty($options['header-mobile-fixed'])) ? $options['header-mobile-fixed'] : 'false';
$fullWidthHeader = (!empty($options['header-fullwidth']) && $options['header-fullwidth'] == '1') ? 'true' : 'false';
$headerColorScheme = (!empty($options['header-color'])) ? $options['header-color'] : 'light';
$userSetBG = (!empty($options['header-background-color']) && $headerColorScheme == 'custom') ? $options['header-background-color'] : '#ffffff';
$trans_header = (!empty($options['transparent-header']) && $options['transparent-header'] == '1') ? $options['transparent-header'] : 'false';
$bg_header = (!empty($post->ID) && $post->ID != 0) ? using_page_header($post->ID) : 0;
$bg_header = ($bg_header == 1) ? 'true' : 'false'; //convert to string for references in css
$perm_trans = (!empty($options['header-permanent-transparent']) && $trans_header != 'false' && $bg_header == 'true') ? $options['header-permanent-transparent'] : 'false';
$headerResize = (!empty($options['header-resize-on-scroll']) && $perm_trans != '1') ? $options['header-resize-on-scroll'] : '0';
$button_styling = (!empty($options['button-styling'])) ? $options['button-styling'] : 'default';
$footer_reveal = (!empty($options['footer-reveal'])) ? $options['footer-reveal'] : 'false';
$footer_reveal_shadow = (!empty($options['footer-reveal-shadow']) && $footer_reveal == '1') ? $options['footer-reveal-shadow'] : 'none';
$has_main_menu = (has_nav_menu('top_nav')) ? 'true' : 'false';
if($headerColorScheme == 'dark') { $userSetBG = '#1f1f1f'; }
$userSetSideWidgetArea = $sideWidgetArea;
if($has_main_menu == 'true' && $mobile_fixed == '1') $sideWidgetArea = '1';
if($headerFormat == 'centered-menu-under-logo') $fullWidthHeader = 'false';
?>
</head>
Mostly the theme header is customized. I don't see any issue in that code. Please guide me how I can resolve this issue.
Here is the w3c validation
You have some comment errors in your html.
First around here: (this is the corrected code)
<!-- [if IE 8]-->
<link rel="stylesheet" type="text/css" href="https://www.accudock.com/wp-content/plugins/js_composer_salient/assets/css/vc-ie8.css" media="screen">
<!--[endif]-->
<!-- BEGIN recaptcha, injected by plugin wp-recaptcha-integration -->
<!-- END recaptcha -->
<!-- WP Facebook Pixel Code - Main -->
Next, remove the <img> tag from the <noscript> tag in head portion here:
<noscript><img alt="" height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=638313929660068&ev=PageView&noscript=1"
/></noscript>
This will solve the stray head tag error.

Page stops loading when reaches <?php echo get_fbimage(); ?> - No solution

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

add opengraph tag in article page

how to add differents meta (opengrapg) tag to every dynamic created page (www.page.com/index.php?page=article&id=1), i tried to put this in article page:
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:og="http://ogp.me/ns#"
xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta property="og:title" content="<?php echo $title?>" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://www.page.com/index.php?page=article&id=<?php echo $id ?>" />
<meta property="og:image" content="http://www.page.com/image.png" />
<meta property="og:site_name" content="eeeeee" />
<meta property="og:description" content="<?php echo $desc; ?>"/>
<meta property="fb:admins" content="blabla" />
</head>
but FB Linter cant see them - "Required Property Missing"
I simple include with switch function article.php page
$conlibrary="play/pages/" ;
IF(!isset($_GET['page'])){
$page = 'deafault';
} ELSE {
$page = $_GET['page'];
$findme = '&';
$pos = strpos($page, $findme);
IF ($pos ===true) {
$data = explode("&", $data);
$dest =$conlibrary."/".$data[0].".php";
IF (file_exists($dest)) {
$page = $_GET['page'];
} ELSE {
$page = '404';
}
} ELSE {
$dest =$conlibrary."/".$page.".php";
IF (file_exists($dest)) {
$page = $_GET['page'];
} ELSE {
$page = '404';
}
}
}
include($conlibrary . $page .".php");
ty
Your missing the ? in your URL...
www.page.com/?page=article&id=1
not
www.page.com/page=article&id=1

Categories