Change WordPress Profile Gravatar to generated robohash - php

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/

Related

Loading wordpress plugin on specific page only

I am developing a plugin for wordpress that loads javascript in a page.
But i want this plugin to load only on selected pages. Not all pages.
Can someone suggest how to do that?
Here is the code.
add_action('wp_enqueue_scripts', 'soundninja_enqueue');
function soundninja_enqueue($hook)
{
wp_enqueue_script('soundninja', // id
'http://soundninja.github.io/SNtest/build/Soundninja.min.js', // path
array('jquery'), // dependencies
0, // appends ?ver=$wordpress_version
true // in_footer
);
}
Another possible workaround would be to keep the plugin deactivated and activate it only for the required pages. This would prevent the additional overhead involved in loading the plugin on pages where the plugin is not required. And most importantly you do not have to tweak the code of the existing plugin.
Here is the post which can give you more idea http://shibashake.com/wordpress-theme/how-to-selectively-load-plugins-for-specific-pages
Depending on where you will call your function soundninja_enqueue($hook) you can easily add an if statement asking if the current page/post id is in an allowed list of ids.
But first you need to get the current page/post id, for this you have a couple of options, depending if are calling the function inside or outside of The loop.
see here on how to get the current page id in wordpress
<?php
$allowedIds = array(12,13,14);
if (in_array($currentID,$allowedIds)) soundninja_enqueue($hook);
Another option is to pass the the current page/post id as a parameter to the function and do the same if test inside the function, your choice.

WP Jetpack publicize insert default text(s)

How can I place a default text (hashtag) in the Custom Message?
The textarea is (located in line 643) under jetpack/modules/publicize/ui.php
I tried to put the text in front of $title in various ways, like:
<?php echo "#myhashtag $title"; ?>
or
<?php echo '#myhashtag '.$title; ?>
but it just echoes the text, not the $title.
Any ideas will be greatly appreciated.
You can use the approach of this Wordpress plugin i made (Publicize With Hashtags), which does exactly that. It basically use and action trigger bound to the 'save_post' native event.
If you want to develop your own one you can have a look at my Source Code on the project's GitHub page or in this installation & usage guide I wrote about it.
You can add a filter, like so, to your theme's functions.php or a site-specific plugin:
add_filter( 'wpas_default_prefix', 'add_default_publicize_hashtag_prefix', 10, 4 );
function add_default_publicize_hashtag_prefix() {
$default_tags = '#yourhastaghere ';
return $default_tags;
}
This will add your default hashtag before your title without you needing to hack the WordPress core.
jetpack/modules/publicize/ui.php itself states in its comments:
/**
* Only user facing pieces of Publicize are found here.
*/
You added your hashtag in the textarea which allows admins to enter a custom message (click edit and it will slide down with your hashtag).
As #Yazmin mentioned, the best way to permanently edit the message is using a filter. The filters available are wpas_default_prefix, wpas_default_message, and wpas_default_suffix.
Personally, I had no success using these filters and I'm interested in a working solution to this issue myself.

Changing Wordpress locale as set by yoast SEO plugin

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

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