This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Contoh Plugin WPLOKAL | |
Plugin URI: https://www.wplokal.com/blog/membuat-plugin-wordpress-sederhana/ | |
Description: Tutorial membuat plugin sederhana | |
Version: 1.0.0 | |
Author: Dodi Hidayatullah | |
Author URI: <a href="https://www.wplokal.com">https://www.langitstudio.com/</a> | |
License: GPL2 | |
License URI: https://www.gnu.org/licenses/gpl-2.0.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ajaxChained(source,target,slug){ | |
$(source).on('change',function(){ | |
var pid = $(source+' option:selected').val(); //$(this).val(); | |
$.ajax({ | |
type: 'POST', | |
url: '{{ site_url() }}psb/'+slug+'/'+pid, | |
dataType: 'html', | |
data: { id : pid }, | |
success: function(txt){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wplokal_before_after($content) { | |
$beforecontent = 'adsense code before content'; | |
$aftercontent = 'adsense code after content'; | |
$fullcontent = $beforecontent . $content . $aftercontent; | |
return $fullcontent; | |
} | |
add_filter('the_content', 'wplokal_before_after'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Columns must be a factor of 12 (1,2,3,4,6,12) | |
$numOfCols = 4; | |
$rowCount = 0; | |
$bootstrapColWidth = 12 / $numOfCols; | |
?> | |
<div class="row"> | |
<?php | |
foreach ($rows as $row){ | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//snippet to get querystring value from url with javascript: | |
function getParameterByName(name, url) { | |
if (!url) url = window.location.href; | |
name = name.replace(/[\[\]]/g, '\\$&'); | |
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), | |
results = regex.exec(url); | |
if (!results) return null; | |
if (!results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, ' ')); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wp_get_attachment( $attachment_id ) { | |
$attachment = get_post( $attachment_id ); | |
return array( | |
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), | |
'caption' => $attachment->post_excerpt, | |
'description' => $attachment->post_content, | |
'href' => get_permalink( $attachment->ID ), | |
'src' => $attachment->guid, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function import_image($post_id, $image_url,$image_name){ | |
// Add Featured Image to Post | |
//$image_url = 'http://s.wordpress.org/style/images/wp-header-logo.png'; // Define the image URL here | |
//$image_name = 'wp-header-logo.png'; | |
$upload_dir = wp_upload_dir(); // Set upload folder | |
$image_data = file_get_contents($image_url); // Get image data | |
$unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name ); // Generate unique name | |
$filename = basename( $unique_file_name ); // Create image file name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 1. create project at https://console.developers.google.com/project | |
* 2. enable 'Analytics API' under 'APIs & auth' / APIs | |
* 3. create 'NEW CLIENT ID' (OAuth client) under 'APIs & auth' / Credentials | |
* i. select 'Service account' | |
* ii. save generated key file to 'key.p12' | |
* iii. remember CLIENT ID | |
* 4. under GA account add 'Read & Analyze' access to newly generated email (access to GA Account not Property nor View) |