IT Blog

  • Blog
  • Technology
    • Technology
    • Architecture
    • CMS
    • CRM
    • Web
    • DotNET
    • Python
    • Database
    • BI
    • Program Language
  • Users
    • Login
    • Register
    • Forgot Password?
  • ENEN
    • 中文中文
    • ENEN
Plugin
Plugin

Add ALT attribute to Social Media Icon

AlT attribute for an image is helpful factor for SEO. But the plugin "Social Media Share Buttons" by Sygnoos is not adding alt attribute for all social images. The following is my approach to add alt attribute to the social images. For this reason, Bing search console is always give a warning message and refuse to index the site. 1. Find possible keyword using browser tool. 2. locate keyword using Visual Studio find feature. Location: /wp-content/plugins/social-media-builder/js/addNewSection/SGMBWidget.js 3. add alt attribute to the images with jQuery. 4. result: Additionary, to set all images ALT value where alt is missing, using this script: Set alt value to image file name where alt is missing $('img').each(function(i,e){ if($(e).attr('alt')=='') $(e).attr('alt', $(e).attr('src').replace(/^.*(\\|\/|\:)/, '').replace(/\.[^/.]+$/,'')); }); How to get this script? Explained below. //show all img src $('img').each(function(i,e){console.log($(e).attr('src'));}); //show all img alt $('img').each(function(i,e){console.log($(e).attr('alt'));}); //get file name from path filepath.replace(/^.*(\\|\/|\:)/, ''); //get file name without extension from file name filename.replace(/\.[^/.]+$/,''); //show all img file name without extension $('img').each(function(i,e){console.log($(e).attr('src').replace(/^.*(\\|\/|\:)/, '').replace(/\.[^/.]+$/,''));}); //set alt value to image file name where alt is missing $('img').each(function(i,e){if($(e).attr('alt')=='') $(e).attr('alt', $(e).attr('src').replace(/^.*(\\|\/|\:)/, '').replace(/\.[^/.]+$/,''));});    999 total views

2021-12-03 0 Comments 337 Views 5 Like IT Team Read more
Plugin

Adding reCaptcha for user forms in WordPress

Google reCAPTCHA uses an advanced risk analysis engine and adaptive challenges to keep malicious software from engaging in abusive activities on your website. UserWP plugin come with anther plugin that support reCaptcha. Here's the steps to setup. Search for UserWP reCaptcha plugin Install and activate UserWP reCaptcha plugin Go to google reCaptcha admin console Find the link to google admin console under Addons tab, and click on the link. Get key from google provider and fill into plugin settings In google admin console, click on plus sign to add a site, then copy the keys. Enter the site key and secret key into plugin settings Check result on the form  3,780 total views,  5 views today

2021-02-08 0 Comments 801 Views 1 Like IT Team Read more
Plugin

WordPress EventCalendar visibility

Based on the official knowledge base, currently there is no “out of the box” way to control events visibility — no plugin setting,  plugin filter,  etc.  But with a bit of custom coding, you can get pretty close. 1. Hide event from month view if the use is not logged in. Ref: https://theeventscalendar.com/knowledgebase/k/making-a-members-only-calendar/ 1. create a event category: Agent Assign the event to the category. 2. add stylesheet, e.g. Custom CSS & JS plugin. .type-tribe_events.tribe-events-category-agent { display: none; } body.logged-in .type-tribe_events.tribe-events-category-agent { display: inline; } 2. disable popup tip window. ref: https://theeventscalendar.com/support/forums/topic/disabling-the-calendar-pop-up-views/ body .tribe-events-calendar .tribe-events-tooltip { visibility:hidden; } @media (max-width: 600px) { body .tribe-events-calendar .tribe-events-tooltip { visibility:hidden; } }    1,601 total views,  5 views today

2020-08-20 0 Comments 378 Views 0 Like IT Team Read more
Plugin

Entering large number of Envira Galleries at a time

Problem Over a few years there are large number of photos in facebook. The MPP want to copy all the photos in facebook to his own gallery on his website. The gallery on the site is using plugin - Envira Gallery. Normally, we create a gallery by drag-drop photos one by one, then place the shortcode on to a post or page. Now we have created all the gallery, the next step is to create posts to acommodate these galleries. The problems left are create posts for each gallery how to please handreds of gallery posts to the menu add featured image to each post Basic informaiton Envira Gallery stores gallery in wp_posts table with post_type = 'envira'. Regular posts are stored in the same table with post_type='post'. The data for the photos in a gallery is stored in wp_postmeta table with meta_key = '_eg_gallery_data' Category information is stored in wp_term_replationships table with object_id = post_id, term_taxonomy_id identifies its category, for gallery term_taxonomy_id=32. Solution Create post list using plugin Advanced Post List. Add posts for each gallery in batch List gallery title, gallery ID in excel in order to generate sql statement to create posts. The formula for cell D3 as following. =$D$1&"(1,'"&YEAR(C3)&"-"&MONTH(C3)&"-"&DAY(C3)&"', '"&YEAR(C3)&"-"&MONTH(C3)&"-"&DAY(C3)&"','[envira-gallery id=\"""&A3&"\""]','"&B3&"','','publish','closed', 'closed','','"&SUBSTITUTE(LOWER(B3)," ","-")&"','','','"&YEAR(C3)&"-"&MONTH(C3)&"-"&DAY(C3)&"','"&YEAR(C3)&"-"&MONTH(C3)&"-"&DAY(C3)&"','',0,'http://domain.com/?page_id=', 0,'post');" The formula on cell C3 as following. ="2018-"&IFERROR(MONTH(LEFT(RIGHT(B3,6),3)&" 1"),MONTH(LEFT(RIGHT(B3,5),3)&" 1"))&"-"&RIGHT(RIGHT(B3,6),2) Change create date for galleries. This is not necessory, but to do this we can use this script in excel cell F3. ="update wp_posts set post_date='"&YEAR(C3)&"-"&MONTH(C3)&"-"&DAY(C3)&"' where id="&A3&";" Set Featured Image to posts Using the first photo in gallery as the featured image.…

2020-03-30 0 Comments 349 Views 0 Like IT Team Read more
Plugin

Adding Featured Image for Envira Gallery posts in batch

Featured Image Featured images are stored in meta_value with meta_key='_thumbnail_id' in wp_postmeta table. SELECT * FROM wp_postmeta WHERE meta_key='_thumbnail_id' and post_id=@post_id Add featured image direct into database Find out the id of the image that you want to be a featured image in wp_post table, then insert a record into wp_postmeta table with meta_key='_thumbnail_id' @image_id = select id from wp_post where post_type='attachment' and post_mime_type='image/jpeg' insert into wp_postmeta (post_id,meta_key,meta_value) values (147, '_thumbnail_id',@image_id); Gallery Photos Photos in Envira Gallery are stored in meta_value with meta_key='_eg_gallery_data' in wp_postmeta table. select * from wp_postmeta where meta_key='_eg_gallery_data' Data stored looks like this: a:3:{s:2:"id";i:3972;s:7:"gallery"; a:8:{i:3973;a:7:{ s:6:"status";s:6:"active"; s:3:"src"; s:102:"http://vincentkempp.com/wp-content/uploads/2020/03/85092119_2768984699811558_8547879668101939200_n.jpg"; s:5:"title";s:47:"85092119_2768984699811558_8547879668101939200_n"; s:4:"link";s:102:"http://vincentkempp.com/wp-content/uploads/2020/03/85092119_2768984699811558_8547879668101939200_n.jpg"; s:3:"alt";s:0:"";s:7:"caption";s:0:"";s:5:"thumb";s:0:"";} Get the first image inside the gallery: SELECT p.id gallery_id, substring(meta_value, locate(':"http://', m.meta_value)+2, locate('";s:5:"title";', m.meta_value)-locate(':"http://',m.meta_value)-2) featured_image FROM wp_posts p JOIN wp_postmeta m on m.post_id=p.id and p.post_type='envira' and p.post_status='publish' and m.meta_key='_eg_gallery_data' ORDER BY p.id Check if the gallery post already has featured image. SELECT m.post_id,post_title, m.meta_value image_id FROM wp_posts p JOIN wp_postmeta m on m.post_id=p.ID and p.post_type='post' and p.post_content LIKE '[envira-gallery id=%' and p.post_status='publish' WHERE meta_key='_thumbnail_id' Get relationship between post_id and gallery_id SELECT p.id,post_title, substring(p.post_content, 21, locate('"]',p.post_content)-21) gallery_id, p.post_content FROM wp_posts p LEFT JOIN wp_postmeta m on m.post_id=p.ID and meta_key='_thumbnail_id' WHERE p.post_type='post' and p.post_content LIKE '[envira-gallery id=%' and p.post_status='publish' and meta_key is null ORDER by p.id Adding featured images INSERT INTO wp_postmeta (post_id,meta_key,meta_value) SELECT p1.id,'_thumbnail_id',img.id FROM ( SELECT p.id,post_title, substring(p.post_content, 21, locate('"]',p.post_content)-21) gallery_id FROM wp_posts p LEFT JOIN wp_postmeta m on m.post_id=p.ID and meta_key='_thumbnail_id' WHERE p.post_type='post' and p.post_content LIKE '[envira-gallery id=%' and p.post_status='publish' and meta_key is null ) p1 -- post_id JOIN ( SELECT p.id gallery_id,…

2020-03-29 0 Comments 648 Views 0 Like IT Team Read more
Plugin

Fix text overlapping in textarea issue

Issue Text entered is overlapped. Cause Stylesheet conflict on line-height and font. Solution Add the following style to custom css: textarea { line-height: 20px !important; } Result  1,945 total views

2019-11-01 0 Comments 635 Views 0 Like IT Team Read more
Plugin

Embeding PDF file on a wp page

To embed a PDF file on a page, follow the following steps. 1. Install plugin: PDF Embedder 2. Config the plugin from its setup. 3. Get shortcode by adding pdf file through "Add Media" button. 4. After add the pdf media we will get the shortcode as following, then click on Publish button: [pdf-embedder url="http://vincentkempp.com/wp-content/uploads/2019/09/News-Release-Recovery-Month-Sept-16-19-v2-zz-.pdf" title="News Release – Recovery Month Sept 16-19 v2-zz"] 5. Result:  1,671 total views,  5 views today

2019-10-27 0 Comments 587 Views 0 Like IT Team Read more
Plugin

Controlling posts order in plugin WP Tab Widget

The plugin "WP Tab Widget" is great widget to display popular posts and recent posts on the sidebar. However, once you installed it you would soon find out that it displays the result with non-sense! Here are the facts: the plugin pick posts randomly, and adds meta_key/value pairs into wp_postmeta table with 2 digits number, as ranking values; the larger meta_value the higher display position on the widget; the actual views of a post do not change the ranking position (do not change the meta_value); actually, the plugin allows you to control the post position displayed in the widget by yourself. You need to manually enter the meta_value of a post into wp_postmeta table, in order to control the display order in the widget. How to reflect the real ranking In order to reflect the real ranking we need to get help with other plugin called Page Views Count. This plugin count every user visit on posts. Run the following script periodically, e.g. daily, hourly. DELETE FROM wp_postmeta WHERE meta_key='_wpt_view_count'; INSERT INTO wp_postmeta (post_id,meta_key,meta_value) SELECT p.id,'_wpt_view_count',t.postcount FROM wp_pvc_total t JOIN wp_posts p on p.id=t.postnum WHERE p.post_type='post' and p.post_status='publish' order by postcount DESC limit 20; -- if you have specific post need to be placed in the first position, run the following delete from wp_postmeta WHERE post_id=6668 and meta_key='_wpt_view_count'; INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES (6668,'_wpt_view_count',99999); Note: To query the order of the posts in the widget, run this query: SELECT p.id,p.post_title,m.meta_value `read` FROM wp_postmeta m JOIN wp_posts p ON p.id=m.post_id WHERE meta_key='_wpt_view_count' ORDER BY CAST(m.meta_value as signed) DESC LIMIT 5 Result:…

2019-04-13 0 Comments 3235 Views 0 Like IT Team Read more
Plugin

Generating XML SiteMap

Search engine robots require sitemap in pure XML format, without any additional content, header, or footer. But WordPress plugin is just for content, when the shortcode being used in pages or posts it will be added with header, menu, and footer automatically. In order to generate pure XML we need to control the output. Using ob_ (output buffer) functions we can achieve this goal, exit() function ignores all following outputs. 1. Add ob_start() to top of header.php file under child theme root folder. 2. Add plugin function to generate sitemap in xml format. function sitemap_post_shortcode($atts) { global $wpdb; $baseurl = 'https://211cn.ca'; $sql = "SELECT concat('$baseurl/',year(post_date),'/',month(post_date),'/',post_name) url ,post_modified from wp_posts WHERE post_type='post' and post_status='publish' order by post_modified DESC"; $result = $wpdb->get_results($sql); $doc = '<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="'. $baseurl .'/wp-content/plugins/albert/sitemap.xsl"?> <!-- generated-on="'. date("Y-m-d\TH:i:s+00:00") .'" --> '; $urlset = $doc.'<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> '; foreach($result as $row) { $urlset .= '<url> <loc>'.$row->url.'</loc> <lastmod>'.date('Y-m-d\TH:i:s+00:00',strtotime($row->post_modified)).'</lastmod> <changefreq>weekly</changefreq> <priority>0.3</priority> </url>'; } $urlset.=" </urlset>"; ob_clean(); echo $urlset; ob_flush(); exit(); } add_shortcode('211postmap', 'sitemap_post_shortcode'); Note that the date in <lastmod> element is required in this format: <lastmod>2019-04-10T11:22:33+00:00</lastmod>, using this code to convert: date('Y-m-d\TH:i:s+00:00',strtotime($row-&gt;post_modified)) Final result  2,040 total views

2019-04-11 0 Comments 890 Views 0 Like IT Team Read more
Plugin

Create Database Tables When Plugin is Activated in WordPress

Googled web, all articles suggested to use register_activation_hook, it does not work for me. For instance, this article "Create Database Tables When Plugin is Activated". It gave out a complete solution as following: $your_db_name = $wpdb->prefix . 'your_db_name';   // function to create the DB / Options / Defaults function your_plugin_options_install() { global $wpdb; global $your_db_name;   // create the ECPT metabox database table if($wpdb->get_var("show tables like '$your_db_name'") != $your_db_name) { $sql = "CREATE TABLE " . $your_db_name . " ( `id` mediumint(9) NOT NULL AUTO_INCREMENT, `field_1` mediumtext NOT NULL, `field_2` tinytext NOT NULL, `field_3` tinytext NOT NULL, `field_4` tinytext NOT NULL, UNIQUE KEY id (id) );";   require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); }   } // run the install scripts upon plugin activation register_activation_hook(__FILE__,'your_plugin_options_install'); However, tried many times with no luck. Finally, use add_action hook and got success. function my_plugin_install() { global $wpdb, $table_name; $charset_collate = $wpdb->get_charset_collate(); if($wpdb->get_var("show tables like '$table_name'") != $table_name) { $sql = "CREATE TABLE wp_moove_activity_log ( id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, post_id bigint(20) UNSIGNED NOT NULL, user_id int(11) DEFAULT NULL, status tinytext, user_ip tinytext, city tinytext, country varchar(255) NOT NULL, post_type tinytext, referer tinytext, campaign_id tinytext, month_year tinytext, display_name tinytext, visit_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY id (id) ) $charset_collate; CREATE TABLE wp_sql (id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, post_id int(11) NOT NULL, `sql` varchar(4000) NOT NULL, `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY id (id) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } } add_action( 'plugins_loaded', 'my_plugin_install' ); Related hooks register_activation_hook ($file, $function) to be run when the plugin is activated register_deactivation_hook ($file,…

2019-01-25 0 Comments 838 Views 0 Like IT Team Read more
1234
Chinese (Simplified) Chinese (Simplified) Chinese (Traditional) Chinese (Traditional) English English French French German German Japanese Japanese Korean Korean Russian Russian
Newest Hotspots Random
Newest Hotspots Random
Rich editor not working Making web page scroll down automatically Getting data from Dapper result All Unicode Chars How to keep and display contact form 7 data Common Regular Expressions
Embed google map in a page Change Event Calendar Title How to automatically translate a website to any language Download URLs Extend some useful string functions in C# Convert UTC time to EST time considering daylight saving time
Categories
  • Architecture
  • BI
  • C#
  • CSS
  • Database
  • DotNET
  • Hosting
  • HTML
  • JavaScript
  • PHP
  • Program Language
  • Python
  • Security
  • SEO
  • Technology
  • Web
  • Wordpress

COPYRIGHT © 2021 Hostlike IT Blog. All rights reserved.

This site is supported by Hostlike.com