phppup Posted February 22, 2023 Share Posted February 22, 2023 I'm not sure whether I'm becoming overindulgent or a real developer, so please advise me. I have several webpages for a new website. I am well acquainted with them and their content. As I began planning to publish these pages, I realized I could probably utilize an array to include meta data for bots and search engines. My thinking was something like: for ($I=0; $I<count($meta); $I++){ if ($page.I){ echo $meta[I] } } I'm concerned with the effectiveness of doing this. Will bots and crawlers see it as legitimate and valid the same as if each page had "hand written" meta data? Or will it flag it as illegitimate or miss it, thereby hurting the pages placement in search results? Not much more to provide since I'm asking the question BEFORE attempting the code. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/315934-meta-data-programmatically/ Share on other sites More sharing options...
Solution gizmola Posted February 22, 2023 Solution Share Posted February 22, 2023 Search engines just look at the final http response data. They have no visibility into the internals of how a page is rendered. There is no problem doing what you want to do, and in fact many cms's, forums and frameworks do this exact thing. Just to be clear, meta tag keywords are ignored by google, so you may or may not want to include those in your page rendering. Quote Link to comment https://forums.phpfreaks.com/topic/315934-meta-data-programmatically/#findComment-1605878 Share on other sites More sharing options...
phppup Posted February 22, 2023 Author Share Posted February 22, 2023 (edited) @gizmola With all due respect, I don't think google is the ONLY search engine on earth. (Sorry, not a fan of theirs, but still fond of you. LOL) Are there any less popular meta tags that I should use (beyond the usual list) or recommended settings to be aware of? Edited February 22, 2023 by phppup Quote Link to comment https://forums.phpfreaks.com/topic/315934-meta-data-programmatically/#findComment-1605891 Share on other sites More sharing options...
cyberRobot Posted February 22, 2023 Share Posted February 22, 2023 For what it's worth, Google also isn't the only search engine that ignores the keywords meta tag when it comes to ranking. Unfortunately, there's too many people willing to pack those meta tags with irrelevant content in order to boost their rankings. Do you consider the description meta tag as part of the "usual list"? The meta tag can be useful for pages that don't have a description paragraph for search engines to display in their results listing. Quote Link to comment https://forums.phpfreaks.com/topic/315934-meta-data-programmatically/#findComment-1605894 Share on other sites More sharing options...
gizmola Posted February 22, 2023 Share Posted February 22, 2023 Google by far generates the most organic search traffic, so it's best to focus on them, as most of the other search engines follow their lead in terms of how they score a page internally. Also the google search console is an excellent tool for getting an idea of what is going on with the indexing of your site. You should make sure you've gone through the steps to insure that every site you control is registered within the tool. The title tag is important. There's a rule of thumb being "12 words/70 character max". Google indexes only the 12 words, weighted towards the first 12. It will also only display up to 70 characters. The description tag is important, only so much as it will be displayed when it comes up in a search result. This is where you can "sell a user" on the relevancy of that page, since the description will show up with the result. Keywords and description are both things that google no longer uses, and were used in the past by people trying to game SEO, by putting in descriptions for pages that don't have relevant content to match the description, or a long list of keywords they "wished" the page in question was relevant for. Any decent search engine these days, parses the content of the page and uses a high degree of sophistication in determining relevance. You aren't going to fool anyone by listing a bunch of key words in the meta tag. Since Google hasn't even looked at them in years, many sites omit them at this point, and if that was a significant concern, you would see discussion of that. Typically if you look at SEO discussion, the main thing that comes up beyond proper use of meta tags is h1's, canonical vs. non-canonical versions of a page, and how to handle those, and having a sitemap (that you re-generate/add to whenever you add a new page to your site.) For indexing pages and internal link collections (for example a page on a blog that has all articles for a particular year, or a page in a catalog where you have all products within a particular category, the robots tag is a good one, and has advantages over using a robots.txt. You don't want non canonical versions of the same page, or pages that could lead to indexing of a non-canonical version along with the canonical version as this has the potential to reduce the overall score for the canonical page. Pages like that should typically include the robots tag. <meta name="robots" content="noindex, nofollow" /> More about that here. If you have video content then you want a video sitemap or mrss feed as described here I know that not all of this is directly related to your meta data question, but hopefully still generally related and useful. Quote Link to comment https://forums.phpfreaks.com/topic/315934-meta-data-programmatically/#findComment-1605895 Share on other sites More sharing options...
cyberRobot Posted February 22, 2023 Share Posted February 22, 2023 As for the code, how is $meta populated? Are you able to get it so $meta only contains the meta tags for the page being viewed? If so, you could skip the loop and do something like this instead echo implode($meta); Quote Link to comment https://forums.phpfreaks.com/topic/315934-meta-data-programmatically/#findComment-1605896 Share on other sites More sharing options...
phppup Posted February 22, 2023 Author Share Posted February 22, 2023 @cyberRobot Yes, I do consider the description tag as one of the "usual." I discovered a meta for security and refresh that I am unfamiliar with and uncertain about. As for you saying Quote too many people willing to pack those meta tags Yes, that was me from way back when. I suppose I owe an apology to everyone that I effected. (although I never got too crazy and NEVER used irrelevant terms) Quote Link to comment https://forums.phpfreaks.com/topic/315934-meta-data-programmatically/#findComment-1605897 Share on other sites More sharing options...
phppup Posted February 22, 2023 Author Share Posted February 22, 2023 I haven't begun to write the actual code yet. Only began to formulate the concept. How would echo implode($meta); work? Quote Link to comment https://forums.phpfreaks.com/topic/315934-meta-data-programmatically/#findComment-1605898 Share on other sites More sharing options...
cyberRobot Posted February 22, 2023 Share Posted February 22, 2023 Here's a quick example: <?php $meta = array( '<meta name="viewport" content="width=device-width, initial-scale=1">', '<meta name="resource-type" content="document">', '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' ); echo implode($meta); ?> Quote Link to comment https://forums.phpfreaks.com/topic/315934-meta-data-programmatically/#findComment-1605899 Share on other sites More sharing options...
phppup Posted February 22, 2023 Author Share Posted February 22, 2023 OK, yes. @cyberRobotThat is in the realm of what I was planning Quote Link to comment https://forums.phpfreaks.com/topic/315934-meta-data-programmatically/#findComment-1605900 Share on other sites More sharing options...
cyberRobot Posted February 22, 2023 Share Posted February 22, 2023 8 minutes ago, phppup said: Yes, that was me from way back when. I suppose I owe an apology to everyone that I effected. (although I never got too crazy and NEVER used irrelevant terms) It was less about the "packing" and more about the irrelevant keywords. So you're good. 😊 Quote Link to comment https://forums.phpfreaks.com/topic/315934-meta-data-programmatically/#findComment-1605901 Share on other sites More sharing options...
phppup Posted February 22, 2023 Author Share Posted February 22, 2023 Quote So you're good @cyberRobotThanks for removing a heavy burden. *not sure what emoji would be appropriate* LOL Quote Link to comment https://forums.phpfreaks.com/topic/315934-meta-data-programmatically/#findComment-1605902 Share on other sites More sharing options...
gizmola Posted February 22, 2023 Share Posted February 22, 2023 You really want to focus on the ones that are programmatic. This is why using a template system like twig or even (back in the old days) smarty is so valuable. Typically this is because you have some sort of database structure where you are entering and configuring attributes related to a page. The title tag is the prime example, even though it is not a meta tag. You also should have a canonical link for all pages, even when that is on a canonical page (pointing back to itself). For example, if you look at the yahoo home page, you find this in the head. <link rel="canonical" href="https://www.yahoo.com/"> As for the meta tags they have the general form of (name, content) so a helper function could be: function makeMeta($name, $content): string { return '<meta name="' . $name . '" content="' . $content . '">' . PHP_EOL; } Quote Link to comment https://forums.phpfreaks.com/topic/315934-meta-data-programmatically/#findComment-1605904 Share on other sites More sharing options...
phppup Posted February 22, 2023 Author Share Posted February 22, 2023 @gizmola Thanks. And yes. Again, I haven't started to write the actual code, but that was my thought process (especially since so many of the tags fit such a similar format. I guess I've actually come quite a way (thanks to those that have helped me HERE). *i wonder if it's time to change my username???!?* 1 Quote Link to comment https://forums.phpfreaks.com/topic/315934-meta-data-programmatically/#findComment-1605905 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.