Adding PHP code to crashes site
-
I am having trouble with adding PHP code to my WordPress weather directly into header.php or using functions.php. All my tests suggest it should produce a valid meta string. Either way if crashes the entire site. It is to add a meta tag for keywords using topics. I get a valid string The code is as follows using functions.php:
function get_my_meta_keywords()
{
// Make sure post
if(is_singular( ‘post’ ) == TRUE)
{
$ID = get_the_ID();
// Make sure we have and ID
if($ID != FALSE)
{
$meta_catagory = get_the_category($ID);
$asize = count($meta_catagory);
// Make sure we have at least one category
if($asize > 0)
{
$category_string = “”;
// Loop through category array
for($i = 0; $i < $asize; $i++)
{
// Add to the category string
$category_string = $category_string.$meta_catagory[$i]->name;
// Add a comma if another category is in array
if($i != $asize – 1)
{
$category_string = $category_string.’,’;
}
}
// Echo the meta tag
echo ‘<meta name=”keywords” content=”‘.$category_string;.'”>’;
}
}
}
}add_action( ‘wp_head’, ‘get_my_meta_keywords’);
I have tried to add this directly in header.php in the meta tag area as simple PHP as follows:
<?php
// Make sure post
if(is_singular( ‘post’ ) == TRUE)
{
$ID = get_the_ID();
// Make sure we have and ID
if($ID != FALSE)
{
$meta_catagory = get_the_category($ID);
$asize = count($meta_catagory);
// Make sure we have at least one category
if($asize > 0)
{
$category_string = “”;
// Loop through category array
for($i = 0; $i < $asize; $i++)
{
// Add to the category string
$category_string = $category_string.$meta_catagory[$i]->name;
// Add a comma if another category is in array
if($i != $asize – 1)
{
$category_string = $category_string.’,’;
}
}
// Echo the meta tag
echo ‘<meta name=”keywords” content=”‘.$category_string;.'”>’;
}
}
}
?> -
Hello there,
Many thanks for reaching out.
Are you able to confirm the URL of the website that you need assistance with please?
Many thanks.
- The topic ‘Adding PHP code to crashes site’ is closed to new replies.