Skip to main content
Share Your Experience: Take the 2024 Developer Survey
30 votes

Add <meta> tags to the <head> section via functions.php

The hook you're looking for is specifically wp_head which could look something like this: function theme_xyz_header_metadata() { // Post object if needed // global $post; // Page ...
Howdy_McGee's user avatar
  • 20.7k
16 votes

How Do I Set the Page Title Dynamically?

As of Wordpress 4.4, you can use the Wordpress filter document_title_parts to change the title. Add the following to functions.php: add_filter('document_title_parts', 'my_custom_title'); function ...
Brendan Nee's user avatar
12 votes

Is sanitize_title enough to generate post slugs?

sanitize_title() seems to be the only one you need. In wp-includes/default-filters.php line 211 you will find: add_filter( 'sanitize_title', 'sanitize_title_with_dashes', 10, 3); This means that ...
Jules's user avatar
  • 1,148
8 votes

How Do I Set the Page Title Dynamically?

For those wishing to change the document's title attribute, I found that using the wp_title filter no longer works. Instead, use the pre_get_document_title filter: add_filter("pre_get_document_title",...
Nathan Arthur's user avatar
7 votes

How Do I Set the Page Title Dynamically?

When having Yoast enabled you need to override the title like so: add_filter('wpseo_title', 'custom_titles', 10, 1); function custom_titles() { global $wp; $current_slug = $wp->request; if ...
leymannx's user avatar
  • 3,161
7 votes

Why does do_robots() Allow: /wp-admin/admin-ajax.php by default?

First: have a read-up on robots.txt, if you haven't. Another good reference is this one from Yoast. The sample you posted: User-agent: * Disallow: /wp-admin/ Allow: /wp-admin/admin-ajax.php Sitemap: ...
Pat J's user avatar
  • 11.9k
6 votes
Accepted

Inserting Post Using wp_insert_post. How to Fill Yoast Plugin SEO Fields

You can use the update_post_meta function to insert the Yoast Plugin data. Yoast uses 3 post meta keys for each post: _yoast_wpseo_title ( use for SEO title ) _yoast_wpseo_focuskw (For meta keywords ...
Syed Fakhar Abbas's user avatar
6 votes

How to rewrite title- and meta-description templates for page templates in Yoast Plugin

You may consider the use of both filter wpseo_metadesc (for meta description) and wpseo_title (for title). The idea is to change the values of title and/or description depending if you meet some ...
Temani Afif's user avatar
5 votes

Is sanitize_title enough to generate post slugs?

Well, there is already an answer, but I wanted to expand it a bit, so here are my findings: If we have a look in wp_insert_post() we see, the $post_name is sanitized using wp_sanitize_title() ( see ...
websupporter's user avatar
  • 2,979
5 votes
Accepted

Block Editor: How to get title and post content within the WordPress admin UI in Javascript?

If we do this in the browser dev tools console: var b = wp.data.select("core/editor"); We can then inspect the b variable to see what functions it exposes via autocomplete, or debugging ...
Tom J Nowell's user avatar
  • 59.4k
4 votes
Accepted

Regenerate images with automatic ALT and TITLE attributes

Full disclaimer, I am the author of the WordPress plugin I am about to mention and I am hoping this answer would give it more visibility. So, I had to do this for a few clients last year mostly for ...
Arun Basil Lal's user avatar
4 votes
Accepted

Disallow author with robots.txt

If you use Yoast SEO, you can go to Users > All Users, and in the Yoast SEO settings, check Do not allow search engines to show this author's archives in search results. See this link. OR With ...
Pim's user avatar
  • 1,152
3 votes

Is sanitize_title enough to generate post slugs?

In addition to websupporter's great answer I found the below: Depending on your usage it will depend what you need. sanitize_title() as it says: accents are removed (accented characters are ...
Brett's user avatar
  • 414
3 votes

Check if SEO plugin installed

You can use the plugin folder name + filename where the plugin is initiated like this for example YOAST plugin: if(in_array('wordpress-seo/wp-seo.php', apply_filters('active_plugins', get_option('...
Jonas Lundman's user avatar
3 votes
Accepted

Why should I use "Organize my uploads into month- and year-based folders" option? (Cons/Pros)

This is one of the many optional features in WordPress.There is no real benefit in using any of these 2 structures, but here is some details for you: Organization: When you are building a website ...
Johansson's user avatar
  • 15.3k
3 votes
Accepted

Changing permalinks structure without loosing SEO

You don't need a plugin to achieve your goal. Use server redirect in the .htaccess file because it will not load the processor to interpret the WordPress PHP code and will not consume time. The ...
Max Yudin's user avatar
  • 6,307
3 votes
Accepted

How to hide sensitve page from google spiders and non-membres in wordpress!

Use password protection mechanism Alterative you can use wordpress hook in your theme to show your post/page only for administrators this way: add_action('wp', function() { if(is_page('my-data') &...
Anton Lukin's user avatar
3 votes
Accepted

how to set title of each page or post for SEO

To properly set the title tag in a theme you shouldn't put it in header.php manually. Your header.php should have wp_head() somewhere between <head></head>, then you can let WordPress set ...
Jacob Peattie's user avatar
3 votes
Accepted

Can I change the contents of a description meta tag generated by Yoast?

Take a look at WordPress SEO API Docs it appears you can modify the meta description tag will somthing like: add_filter('wpseo_metadesc', function($description){ if ($wtv_language == 'wtv') { ...
David Sword's user avatar
  • 3,327
3 votes
Accepted

Is <title> tag default in WordPress?

Well, it's not a stupid question at all... wp_title is a template tag and it was used for a long time (since 1.0.0) to put <title> tag in the header. This way plugins were able to modify the ...
Krzysiek Dróżdż's user avatar
3 votes
Accepted

how to base64 encode images in wordpress template

in your file functions.php in your template put this funcitons /** * @param $path * @return string * @author https://github.com/ozzpy */ function imageEncode($path) { $path = __DIR__."/".$path; $...
rafaelphp's user avatar
  • 146
3 votes
Accepted

Seo Friendly Filter URLs

Yes, it is possible. Option 1: Programmatically using add_rewrite_rule() Add the rewrite rule: /* The rule matches: * example.com/product-category/rings/rings-in-gold/ * example.com/product-...
Sally CJ's user avatar
  • 39.3k
3 votes

Why does do_robots() Allow: /wp-admin/admin-ajax.php by default?

the truth is that probably nothing should be blocked in robots.txt by core (this is IIRC was joost's position abot the matter) as wordpress is an open platform and front end content and styling might ...
Mark Kaplun's user avatar
  • 23.4k
2 votes

Robots.txt not updating

I had the same issue and for me, I had to purge the Cloudflare cache.
Vahid's user avatar
  • 179
2 votes
Accepted

Seo Wordpress Pages on google

First thing: When searching for costruzioniao google thinks you just misspelled costruzioni. It doesn't think of it as being an independent search term yet. This should get better with time, ...
JHoffmann's user avatar
  • 1,850
2 votes

Is it okay to use page template as contact page?

Yes, you can use page template for your contact page. Page templates have nothing to do with SEO. The contents inside the page template do.
Minh Tri's user avatar
  • 3,419
2 votes

Why should I use "Organize my uploads into month- and year-based folders" option? (Cons/Pros)

OMG, is there nothing else in the world except for SEO this days? Each OS has limitations and/or performance degradation on the number of files that are in a directory. used to be a limit of 32k ...
Mark Kaplun's user avatar
  • 23.4k
2 votes

How can I modify the <header> element on all pages?

The <header> elements are usually echoed directly by the theme. So without any hook or filter to change them. In that case, there is no way to change those elements with a function. Check your ...
cjbj's user avatar
  • 14.6k
2 votes
Accepted

add the post as canonical for attachment page wordpress

Here's an (untested) example where we inject into the header tag on attachment's pages, the canonical link of the attached post: add_action( 'wp_head', 'wpse_attachment_parent_canonical' ); function ...
birgire's user avatar
  • 67.4k
2 votes
Accepted

Facebook og:image issues after https change

The https change was not the cause. Actually - coincidentally - the W3 Total Cache was updated on the same day, and the Minify setting was breaking lines between meta and property words on the HTML, ...
Adriano Castro's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible