Changing Wordpress locale as set by yoast SEO plugin - php

My WordPress site is based in Great Britain. I was able to change the html lang-attribute from en-US to en-GB, however when I view my source code the og:locale attribute of open graph displays as en-US, it is generated by yoast SEO plugin. Is there a way to change locale to en-GB?

From the documentation:
wpseo_locale (string)
Allows changing the locale used in the opengraph set (and possibly in other locations later on).
Here's a specific example of how someone else solved it in functions.php:
add_filter('wpseo_locale', 'override_og_locale');
function override_og_locale($locale)
{
return "en_GB";
}

Related

Get full rendered Wordpress page with WPML via REST API

I've made a Laravel-Wordpress connection for a project. For this connection, I use the Worpdress REST API.
I'm able to get specific pages from Laravel with the header and footer from Wordpress via API (for a uniform look) and other pages comes completely from Wordpress. Big benefit is, that Wordpress pages can be edited with the pretty user-friendly Wordpress backend while other pages can be custom coded in Laravel.
To achieve this, I have added some new API endpoints to retrieve the rendered header / footer and a complete page:
add_action('rest_api_init', function () {
// add 'rendered_page' member with complete HTML for requested page
register_rest_field(
'page',
'content',
array(
'get_callback' => 'by_render_page_content',
'update_callback' => null,
'schema' => null,
)
);
// add new endpoint for getting header and footer
register_rest_route('eeg/v1', '/headerandfooter', array(
'methods' => 'GET,POST',
'callback' => 'get_page_header_and_footer',
));
});
The callbacks look like this: (i.e. for the complete page)
if (isset($request['language'])) {
do_action('wpml_switch_language', $request['language']);
}
$file = THEME_DIR . '/single.php';
ob_start();
include $file;
return ob_get_clean();
As you can see, I'm checking for a language parameter and set the current language of the WPML plugin with wpml_switch_language hook.
This seems to work 'a little bit'. So, for example, the language switcher shows the correct current language.
The problem is, in the main menu: All links are showing to default language. For example if currently selected language is english, the links should look like mydomain.com/en/requestedpage. But all links go to the default mydomain.com/requestedpage. Also the <html lang> parameter is set to the default language, not to the requested. And also the <link hreflang> tags from WPML are missing.
If I access the page via the Wordpress Frontend (which is hosted at a subdomain), everything is working correctly.
So I think, I have to set the requested language somewhere else or have to call some WPML 'prepare' hooks or something like that, to make this work. Maybe also the include './single.php'; is not the right way to do this.
Any hint is welcome.
I could fix it by myself.
The solution was to create a translated menu with WPML.
In Wordpress frontend, the links in the menus are localized also without an extra translated menu. But for this scenario with the REST API, a translated menu is necessary.

Change WordPress Profile Gravatar to generated robohash

By default, WordPress admin section allows us to choose from the following Gravatar options:
Mystery Person, Blank, Gravatar Logo, Identicon (Generated), Wavatar (Generated), MonsterID (Generated), Retro (Generated)
However, when I visit https://en.gravatar.com/site/implement/images/. I can see an option for generated robohash. All I have to do is replace wavatar in all image URLs with robohash.
https://secure.gravatar.com/avatar/b7556ca086c0d99f2000b73e8f4ce4ea?s=96&d=wavatar&r=g
// will become
https://secure.gravatar.com/avatar/b7556ca086c0d99f2000b73e8f4ce4ea?s=96&d=robohash&r=g
I can do it on my own vanilla PHP website because I have full control over the HTML on a page. However, I don't know how to use robohash avatars on a site with WordPress installation.
First, I thought that I can use JavaScript to select all images on a page and then replace wavatar with robohash but it seems very unWordPress like and error prone.
Is there a clean and efficient way of doing this like using add_filter() etc.?
Thanks.
I have changed a default to my custom rest of you need to manage.There below code will change default gravatar:
add_filter( 'avatar_defaults', 'set_new_gravatar' );
function set_new_gravatar($avatar_defaults) {
$myavatar = 'http://example.com/wp-content/uploads/2017/01/new-default-gravatar.png'; // response image URL
$avatar_defaults[$myavatar] = "Default Gravatar";
return $avatar_defaults;
}
There is plugin for this : https://wordpress.org/plugins/robohash-avatar/

Yoast SEO | How to create custom variables

Was just wondering if there is a way to create a custom variable so that I can add my custom variable created in the Meta title of the page.
Yoast SEO has a list of variables predefined here.
It would be great if I could create a variable of my own. Is there any way to get this?
Thanks in advance!
You have two options for this.
Add filter for change exist variable.
Add your new custom variable.
If you want to change exist variable, you can do it like this:
// define the wpseo_replacements callback
function filter_wpseo_replacements( $replacements ) {
if( isset( $replacements['%%page%%'] ) ){
$replacements['%%page%%'] = 'Page x of y';
}
return $replacements;
};
// Add filter
add_filter( 'wpseo_replacements', 'filter_wpseo_replacements', 10, 1 );
And if do you want to add custom variable you can do it like this:
// define the custom replacement callback
function get_myname() {
return 'My name is Moses';
}
// define the action for register yoast_variable replacments
function register_custom_yoast_variables() {
wpseo_register_var_replacement( '%%myname%%', 'get_myname', 'advanced', 'some help text' );
}
// Add action
add_action('wpseo_register_extra_replacements', 'register_custom_yoast_variables');
I hope I was helpful to you.
There is a way, but as far as I know, you must get a Premium account in Yoast Seo. One of the most important functions of both Yoast SEO and Yoast SEO Premium is the possibility to add title templates and meta description templates to the homepage, all (custom) post types, all (custom) taxonomies and other pages.
Note: Template variables can also be used on individual posts, pages and taxonomies.
Setting up / changing your templates
You can change your title & meta templates by going to the admin of your WordPress installation and clicking SEO → Titles & Metas.
Log in to your WordPress website. When you're logged in, you will be in your 'Dashboard'. On the left-hand side, you will see a menu. In that menu, click on 'SEO'.
The 'SEO' settings will expand providing you additional options. Click on 'Titles & Metas'.
Under each tab, you can use these variables to create templates for various pages within your site.
You can use the variables from the partial list below to create your own templates for the titles and meta-descriptions. The full list of variables is listed on the HELP tab of the plugin. Just go to SEO → Titles & Metas and click the help tab in the top right.
For more about that and see many images of the process, please visit this page: http://kb.yoast.com/article/146-yoast-wordpress-seo-titles-metas-template-variables

how to filter "link to existing content" suggestion in wordpress?

How can i filter the link given in "link to existing content".
As in the above image. I just want WSP BANNER TO BE SHOWN.
where WSP BANNER & CALENDAR are custom post_type
Any help will be appreciable.
Currently there are no ready filters available for this purpose. A ticket has been posted for the request.Lets hope we get one soon.
Till then you can create your own filter.
Open includes/class-wp-editor.php and make folowing changes at line no 712
$pt_names = apply_filters('custom_insert_link_suggestion_filter',array_keys( $pts ));
we just added a new filter instead of getting all the public post types
Then in your theme add following code to filter the internal link custom post type
function my_filter_function($allowed_post_types)
{
if( condition chek)
{
return array('page','your custom post types');
}
}
add_filter('custom_insert_link_suggestion_filter','my_filter_function',10,1);
There is a plugin that could be helpful for you: B09 Link to Existing Content
It has a filter called "link_to_existing_content_post_types", that enables you to control which post types should be searched.
You can also use it together with this plugin, if you also want to have complete control over the search results: Search Everything.
Consider an example where my site is configured on wp.abc.com and I point my root domain www.abc.com to the new site. I need to update the URL's in General Setting. So when I update the URL, it is reflected in menu items etc. Will it be reflected in the content area links aslo?

Custom Taxonomy Term page in Drupal 7

I'm trying to make a custom Taxonomy Term page in Drupal 7. I've created a page--taxonomy.tpl.php file in my templates folder. The file only prints out a message. I now try to force the template file by adding
function template_preprocess_page($variables) {
if (arg(0) == 'taxonomy') {
$variables['template_file'] = 'page--taxonomy-tpl';
}
}
in my template.php, but it won't work. Can you help me? And if I get the custom page working, how do I fetch the nodes with this term (in page--taxonomy.tpl.php)? Thanks in advance.
Try using this in your template.php:
function template_preprocess_page(&$variables) {
if (arg(0) == 'taxonomy') {
$variables['theme_hook_suggestions'][] = 'page__taxonomy';
}
}
You need to pass $variables by reference, so add a & before it
template_file has changed to theme_hook_suggestions in Drupal 7
You don't need the -tpl in the template suggestion unless you want it to be a part of the filename like "page--taxonomy-tpl.tpl.php" which I don't think is what you want.
For more information, check out template_preprocess_page(), theme_get_suggestions() and Working with template suggestions
Not sure if this would meet your requirements, but one of default D7 views - Taxonomy term - emulates Drupal core's handling of taxonomy/term pages. You could just enable it (it would automatically replace Drupal's core taxonomy URLs), and then do whatever you want with it, keeping original page structure, all blocks etc, using Views' page templates (see "Theming information" in "Advanced") and all other bells and whistles...
Since you are using Drupal 7, you could also create a file name "taxnomy-term.tpl.php" and edit according to your needs.
See taxonomy-term.tpl.php
Full control over the taxonomy term page can be obtained using hook_menu_alter() . See https://drupal.stackexchange.com/questions/48420/theming-and-overriding-taxonomy-term-vocabulary-page/111194#111194

Categories