Hot answers tagged

19

So as noted in the comments above, I found a solution and used this code to do it: function remove_yoast_metabox_reservations(){ remove_meta_box('wpseo_meta', 'reservation', 'normal'); } add_action( 'add_meta_boxes', 'remove_yoast_metabox_reservations',11 ); In this instance, "reservation" was my custom post type. And "wpseo_meta" was the ID of the ...


14

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 conditional if needed // if( is_page() ){} ?> <meta name="abc" content="xyz" /> <?php } add_action( 'wp_head', 'theme_xyz_header_metadata' ...


12

Although I would advice you to avoid this and use a plugin for this work. Because only a dedicated plugin can help SEO. "WordPress SEO" from yoost is a great plugin for SEO. That being said, here is the code for adding meta description and keywords in header. Paste this in theme's functions.php file. function add_meta_tags() { global $post; if ( ...


10

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 my_custom_title( $title ) { // $title is an array of title parts, including one called `title` $title['title'] = 'My new title'; if (is_singular('post')) {...


8

You'll find this post by Joost De Valk on changing WordPress permalinks to only include /%postname% very helpful. How many posts you have doesn't matter anymore if you are using the latest version of WordPress (at least > v3.3.1). I believe your permalink structure initially was — this /blog/%year%/%monthnum%/%day%/%postname%/ — and now, you are planning ...


7

By default the plugins are ranked by "relevance" and the only people who know how that algorithm is weighted work for wordpress.org (it's doubtful they are going to let anyone in on it). Downloads and rating are not the main components, just one of many including keywords, date, and how many beers you buy Otto. You don't have any options to rank high ...


6

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", "my_callback"); function my_callback($old_title){ return "My Modified Title"; } Source


6

Your rule works with the attachment ID, so I'm not sure how you're using the title, but the answer is almost identical in either case. The filter you want is attachment_link: function wpd_attachment_link( $link, $post_id ){ $post = get_post( $post_id ); return home_url( '/images/' . $post->post_title ); } add_filter( 'attachment_link', '...


5

From the WordPress SEO FAQ: ... either enable "Force rewrite titles" on the SEO -> Titles settings page, or go into your header.php and change the title element to just this: <title><?php wp_title(''); ?></title> Did you try that?


5

Check your theme (header.php). If it uses something like this : <title><?php wp_title( '|', true, 'right' ); ?></title> You can use this filter : add_filter( 'wp_title', 'wpse104667_wp_title' ); function wpse104667_wp_title( $title ) { global $post; if( is_singular() && !is_front_page() && !...


5

If the comment is a pingback or a trackback and short_ping is true then the comment is processed by the ping method which formats the comment differently than either the html5_comment method or the comment method both of which create a much longer more complicated format than does the very minimal ping method. You can kind-of guess what it does by the name ...


4

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 calling sanitize_title() will first remove all the special characters, then apply the sanitize_title filter, thus calling sanitize_title_with_dashes() As @...


4

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 wp-includes/post.php) In the function sanitize_title() we have a filter sanitize_title. This is interesting, since in the default filters ...


4

Yoast uses wp_head hook to output the meta description tag. Make sure you have this line in your <head>: <?php wp_head(); ?> For title tag, you can simplify the code by using one function call: <?php wp_title( '|', true, 'right' ); ?> The wp_title uses a filter (same name wp_title) to let users change the title tag. And Yoast uses this ...


4

To allow crawling of your WP site you need to go to "admin panel >> Settings >> Reading" right before the "Save Changes" button is a checkbox with the label Search Engine Visibility make sure this is unchecked.


4

General WordPress rule: when a function starts with get, it will return the value. If it starts with the, it echoes the value. Here, you need get_the_date('d-m-Y') instead of the_date('d-m-Y').


4

WordPress select template, following its Template Hierarchy logic. What you have that is category archive, templates for individual pages are never considered for it. Also.. with the view of SEO, page.php is more important then category.php.. right? PHP template file is entirely back-end concepts, it doesn't have anything to do with SEO inherently.


4

Thought this was a great question so I went digging. In default-filters.php on line 208 there's add_action('wp_head', 'noindex', 1); as of WordPress 4.1. The noindex() function in turn checks to see if you have set blog_public option to 0. If you have, it calls wp_no_robots() which is simply: function wp_no_robots() { echo "<meta name='robots' ...


4

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 ) _yoast_wpseo_metadesc (For meta descriptio ) You can find all these meta key under postmeta table $new_id = wp_update_post($array); ...


3

It is my understanding that there should not be more than one <h1> tag on a page, and that the <h1> tag should be the site title, for SEO reasons. But that’s your opinion, not a rule. From an accessibility perspective the h1 should be used for main content’s title, on a single page that is the post title, on a list (archive), the archive title. ...


3

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 ($current_slug == 'foobar') { return 'Foobar'; } }


3

I would not trust your SEO contractor on this one. The reason Wordpress does that by default is to attempt to feed search engines a page name that has words in it rather than an arbitrary database location. Google can use the words semantically to attempt to classify the page; whereas, they can't if the page is called ?p=31245 or whatever. Having all those ...


3

In order to play nicely with Plugins or other code that attempts to modify the HTML document title content (i.e. wp_title() output), you should always and only output this: <title><?php wp_title( '' ); ?></title> ...and if you want to modify that output yourself, filter wp_title instead of hard-coding anything inside the <title></...


3

You can use the wpseo_title filter to read the tag for your site title after WPSEO creates it, and if it's not there, add it on. add_filter( 'wpseo_title', 'wpse137502_wpseo_title' ); function wpse137502_wpseo_title( $title ) { $site_title = get_bloginfo( 'name' ); if ( ! strpos( $title, $site_title ) ) { $title .= " | " . $site_title; }...


3

Below is a small plugin using which you should be able to replace the domain for canonical url to another domain. <?php /* * Plugin Name: WPSE WPSEO Canonical * Plugin URI: http://wordpress.stackexchange.com * Description: Changes canonical url domain. * Author: Sisir * Version: 1.0 * Author URI: http://developerpage.net * **/ add_filter('...


3

If your entire page fits in the 4GB LONGTEXT post content field, the limit to the number of pages would be related to the amount of RAM available on your server. When a multipage post is loaded, it is exploded on <!--nextpage--> to put your post into an array of individual pages, so at that point your single page load is consuming at least twice the ...


3

There are different ways to achieve this. Google tries to automatically extract the publish date of an article you wrote. The most common and easiest way for Google is to use rich snippets: http://schema.org/Article See "datePublished" - property for this. After you implemented these little HTML-snippets you can test your markup using the Rich Snippet ...


3

Here is a safe and Yoast preferred method add_action('wp_head','add_custom_meta_description_box'); function retrieve_var1_replacement( $var1 ) { global $post; return strip_tags($post->post_content); } function register_my_plugin_extra_replacements() { wpseo_register_var_replacement( '%%mycustomdesc%%', 'retrieve_var1_replacement', '...


3

You cad add it via functions.php with a hook, instead of inside the loop (you don't really want to add a loop to header.php): function add_author_meta() { if (is_single()){ global $post; $author = get_the_author_meta('user_nicename', $post->post_author); echo "<meta name=\"author\" content=\"$author\">"; } } ...


3

Once I experienced the same issue, this is what I did to fix the issue. Edit the robots.txt file directly (using FTP/SSH), User-agent: * Disallow: /wp-admin/ Disallow: /wp-includes/ There are two reasons if the robots files not updated when you edited using a plugin. File permission. Some other plugin is reverting the changes. Also try to update the ...


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