Hot answers tagged

22

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 ...


15

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')) {...


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

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 @...


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

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'; } }


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

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

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

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

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

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 ...


3

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 redirect will be completed before the WordPress runs. RewriteRule ^[0-9]+/[0-9]+/(.*)\.html$ /$1 [R=301,L] Where [0-9]+/ is the numeric year and month (.*) is the ...


3

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') && !current_user_can('manage_options')) die("123") }); Note: don't use this code. It is just for demonstration. Better use hook template_redirect ...


3

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 condition. So your code will look to somthing like this: add_filter('wpseo_metadesc','custom_meta'); function custom_meta( $desc ){ if (/* do your test here ...


3

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 the title tag by adding support for title-tag to your theme: function wpse_304818_theme_setup() { add_theme_support( 'title-tag' ); } add_action( '...


3

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 title with filters. In WP 4.4 it was about to be deprecated, but that idea was abandoned and you can still use that function. On the other hand, you don't have ...


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