{"id":29,"date":"2018-02-01T03:16:23","date_gmt":"2018-02-01T03:16:23","guid":{"rendered":"http:\/\/api.intelligentonlinetools.com\/diy\/?p=29"},"modified":"2018-02-06T13:53:07","modified_gmt":"2018-02-06T13:53:07","slug":"create-custom-plugin-in-wordpress-referrer-url","status":"publish","type":"post","link":"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/","title":{"rendered":"How to Create Custom Plugin in WordPress to Get Referrer URL"},"content":{"rendered":"<p>Seventy-four percent of online consumers get frustrated when a website promotes content that isn&#8217;t applicable to their interests. [1] How can we know customer interests? When new user arrives to website we can get the previous site url that the user visited. Such previously visited page by web visitor is called <em>referrer<\/em>. If we have browsing history of users from the same or similar websites we  can use some patterns for new users. <\/p>\n<p>Since my site is using WordPress platform I decided to build wordpress plugin to be able manipulate content or ads based on web user referrer url. (In the code this term is used as <em>referer<\/em>) This is my first WordPress plugin and I found creation of it is much easy than I thought.<\/p>\n<h3>How to Use Plugin<\/h3>\n<p>One of possible use of this wordpress custom plugin (in pseudo code): <\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nif referrer url is google\r\n     show some ad for google visitors \r\nif referrer url is website ABC\r\n     show some different ad or content\r\nif none of the above\r\n     show some default ad\r\n<\/pre>\n<p>Below I put the steps that I used to create custom plugin in wordpress.  This plugin is just getting user referrer and displaying this information. You would need insert some actions based on referrer url as per example in pseudo code above.<\/p>\n<h3>Steps How to Create Custom Plugin in WordPress to Get Referrer URL<\/h3>\n<p>1. Go to your web hosting account where wordpress is installed and create folder get_referer_widget under plugins folder. Put blank file init.php in the new created folder. So here how the folder structure will look:<br \/>\nyour_blog_name_folder<br \/>\n|&#8212;wp-content<br \/>\n|&#8212;&#8212;plugins<br \/>\n|&#8212;&#8212;&#8212;&#8211;get_referer_widget<br \/>\n|&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;init.php<\/p>\n<p>2. In the file init.php we need define name of our plugin, class and register our plugin. The full php source code for file init.php is provided in the end of this post.<\/p>\n<p>3. To get referer we can use wordpress function wp_get_referer:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php \r\nif ( wp_get_referer() )\r\n{\r\n    echo ( wp_get_referer() );\r\n    \/\/  based on referer show some ads or content\r\n \r\n}\r\nelse\r\n{\r\n   echo &quot;default action&quot;;\r\n  \/\/ do default action as referrer url is not available\r\n}\r\n?&gt;\r\n<\/pre>\n<p>4. Go to plugins section in wordpress admin and activate newly installed plugin.<\/p>\n<figure id=\"attachment_37\" aria-describedby=\"caption-attachment-37\" style=\"width: 1014px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/02\/get_referer_plugin-1024x80.jpg\" alt=\"get_referer_plugin widget activation\" width=\"1024\" height=\"80\" class=\"size-large wp-image-37\" srcset=\"http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/02\/get_referer_plugin-1024x80.jpg 1024w, http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/02\/get_referer_plugin-300x23.jpg 300w, http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/02\/get_referer_plugin-768x60.jpg 768w, http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/02\/get_referer_plugin.jpg 1074w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption id=\"caption-attachment-37\" class=\"wp-caption-text\">get_referer_plugin widget activation<\/figcaption><\/figure>\n<p>5. Go to widgets tab and add widget <em>Get Referer Widget<\/em> for some available area.<\/p>\n<figure id=\"attachment_38\" aria-describedby=\"caption-attachment-38\" style=\"width: 232px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/02\/get_referer_widget.jpg\" alt=\"Plugin screen view with installed get_referer_widget plugin\" width=\"242\" height=\"70\" class=\"size-full wp-image-38\" \/><figcaption id=\"caption-attachment-38\" class=\"wp-caption-text\">Get_referer_widget plugin on the widgets screen<\/figcaption><\/figure>\n<p>6. Test widget: first time when you access page it will show default option, but then if you click some link on this page you should see the link of this previous page.<\/p>\n<p>7. Now when testing is completed you can put actual actions in it.<br \/>\n8. If you want to stop use this wordpress custom plugin you can deactivate it in wordpress plugin manager.<\/p>\n<p>Here is the source code for init.php<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n\/*\r\nPlugin Name: Get Referer Widget\r\nDescription: This plugin provides a simple widget that shows the referrer url of user\r\n*\/\r\nclass get_referer_widget extends WP_Widget {\r\n    function Get_Referer_Widget() {\r\n    parent::WP_Widget(false,'Get Referer Widget');\r\n    \r\n    }\r\n    \r\n    function widget($args) {\r\n        \r\n    if ( wp_get_referer() )\r\n    {\r\n        $msg= wp_get_referer() ;\r\n    }\r\n    else\r\n    {\r\n       $msg = &quot;default&quot;;\r\n    }\r\n\r\n        echo $before_widget;\r\n        echo &quot;&lt;p&gt;$msg&lt;\/p&gt;&quot;;\r\n        echo $after_widget;\r\n       }\r\n    }\r\n    function register_get_referer_widget() {\r\n        register_widget('Get_Referer_Widget');\r\n        \r\n    }\r\n    add_action('widgets_init', 'register_get_referer_widget');\r\n?&gt;\r\n<\/pre>\n<p><strong>Conclusion<\/strong><br \/>\nWe have seen how to create custom plugin in wordpress to get referrer url. Referring website url can be used to show different ad or content. It can be also used for referral analytics.<br \/>\n<strong>References<\/strong><\/p>\n<p>1. <a href=\"https:\/\/blog.hubspot.com\/marketing\/website-personalization-examples-dynamic?__hstc=236787550.4d987c2757e436c64d86767a487d9a26.1517453312203.1517453312203.1517453312203.1&#038;__hssc=236787550.1.1517453312203&#038;__hsfp=3647517780\" target=\"_blank\">website-personalization-examples-dynamic<\/a><br \/>\n2. <a href=\"https:\/\/codex.wordpress.org\/Function_Reference\/wp_get_referer\" target=\"_blank\">wp_get_referer<\/a><br \/>\n3. <a href=\"http:\/\/www.wpbeginner.com\/wp-tutorials\/how-to-create-a-custom-wordpress-widget\/\" target=\"_blank\">How to Create a Custom WordPress Widget<\/a><br \/>\n4. WordPress for Dummies.   Lisa Sabin-Wilson <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Seventy-four percent of online consumers get frustrated when a website promotes content that isn&#8217;t applicable to their interests. [1] How can we know customer interests? When new user arrives to website we can get the previous site url that the user visited. Such previously visited page by web visitor is called referrer. If we have &#8230; <a title=\"How to Create Custom Plugin in WordPress to Get Referrer URL\" class=\"read-more\" href=\"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/\" aria-label=\"More on How to Create Custom Plugin in WordPress to Get Referrer URL\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false},"categories":[10],"tags":[11,13,12],"aioseo_notices":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Create Custom Plugin in Wordpress to Get Referrer URL - Using Web API with Python<\/title>\n<meta name=\"description\" content=\"How to create custom plugin in wordpress to show web user referrer url. Build wordpress simple plugin to do referral analytics, display ads or content based on user referring website\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Custom Plugin in Wordpress to Get Referrer URL - Using Web API with Python\" \/>\n<meta property=\"og:description\" content=\"How to create custom plugin in wordpress to show web user referrer url. Build wordpress simple plugin to do referral analytics, display ads or content based on user referring website\" \/>\n<meta property=\"og:url\" content=\"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/\" \/>\n<meta property=\"og:site_name\" content=\"Using Web API with Python\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-01T03:16:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-02-06T13:53:07+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/02\/get_referer_plugin-1024x80.jpg\" \/>\n<meta name=\"author\" content=\"owygs156\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"owygs156\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/\",\"url\":\"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/\",\"name\":\"How to Create Custom Plugin in Wordpress to Get Referrer URL - Using Web API with Python\",\"isPartOf\":{\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/#website\"},\"datePublished\":\"2018-02-01T03:16:23+00:00\",\"dateModified\":\"2018-02-06T13:53:07+00:00\",\"author\":{\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/#\/schema\/person\/6788923b31e0ea6b3bfa2c079adb1332\"},\"description\":\"How to create custom plugin in wordpress to show web user referrer url. Build wordpress simple plugin to do referral analytics, display ads or content based on user referring website\",\"breadcrumb\":{\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/api.intelligentonlinetools.com\/diy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create Custom Plugin in WordPress to Get Referrer URL\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/#website\",\"url\":\"http:\/\/api.intelligentonlinetools.com\/diy\/\",\"name\":\"Using Web API with Python\",\"description\":\"Using Web API with Python\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/api.intelligentonlinetools.com\/diy\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/#\/schema\/person\/6788923b31e0ea6b3bfa2c079adb1332\",\"name\":\"owygs156\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/api.intelligentonlinetools.com\/diy\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g\",\"caption\":\"owygs156\"},\"url\":\"http:\/\/api.intelligentonlinetools.com\/diy\/author\/owygs156\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Create Custom Plugin in Wordpress to Get Referrer URL - Using Web API with Python","description":"How to create custom plugin in wordpress to show web user referrer url. Build wordpress simple plugin to do referral analytics, display ads or content based on user referring website","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Custom Plugin in Wordpress to Get Referrer URL - Using Web API with Python","og_description":"How to create custom plugin in wordpress to show web user referrer url. Build wordpress simple plugin to do referral analytics, display ads or content based on user referring website","og_url":"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/","og_site_name":"Using Web API with Python","article_published_time":"2018-02-01T03:16:23+00:00","article_modified_time":"2018-02-06T13:53:07+00:00","og_image":[{"url":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-content\/uploads\/2018\/02\/get_referer_plugin-1024x80.jpg"}],"author":"owygs156","twitter_card":"summary_large_image","twitter_misc":{"Written by":"owygs156","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/","url":"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/","name":"How to Create Custom Plugin in Wordpress to Get Referrer URL - Using Web API with Python","isPartOf":{"@id":"http:\/\/api.intelligentonlinetools.com\/diy\/#website"},"datePublished":"2018-02-01T03:16:23+00:00","dateModified":"2018-02-06T13:53:07+00:00","author":{"@id":"http:\/\/api.intelligentonlinetools.com\/diy\/#\/schema\/person\/6788923b31e0ea6b3bfa2c079adb1332"},"description":"How to create custom plugin in wordpress to show web user referrer url. Build wordpress simple plugin to do referral analytics, display ads or content based on user referring website","breadcrumb":{"@id":"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/api.intelligentonlinetools.com\/diy\/create-custom-plugin-in-wordpress-referrer-url\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/api.intelligentonlinetools.com\/diy\/"},{"@type":"ListItem","position":2,"name":"How to Create Custom Plugin in WordPress to Get Referrer URL"}]},{"@type":"WebSite","@id":"http:\/\/api.intelligentonlinetools.com\/diy\/#website","url":"http:\/\/api.intelligentonlinetools.com\/diy\/","name":"Using Web API with Python","description":"Using Web API with Python","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/api.intelligentonlinetools.com\/diy\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/api.intelligentonlinetools.com\/diy\/#\/schema\/person\/6788923b31e0ea6b3bfa2c079adb1332","name":"owygs156","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/api.intelligentonlinetools.com\/diy\/#\/schema\/person\/image\/","url":"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g","contentUrl":"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g","caption":"owygs156"},"url":"http:\/\/api.intelligentonlinetools.com\/diy\/author\/owygs156\/"}]}},"_links":{"self":[{"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/posts\/29"}],"collection":[{"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/comments?post=29"}],"version-history":[{"count":21,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/posts\/29\/revisions"}],"predecessor-version":[{"id":170,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/posts\/29\/revisions\/170"}],"wp:attachment":[{"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/media?parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/categories?post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/api.intelligentonlinetools.com\/diy\/wp-json\/wp\/v2\/tags?post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}