Skip to content

Instantly share code, notes, and snippets.

View wplokal's full-sized avatar

Dodi Hidayatullah wplokal

View GitHub Profile
<?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');
@wplokal
wplokal / Loop Row with Colum Bootstrap.php
Created March 19, 2019 03:01
Loop Row with Colum Bootstrap - PHP
<?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){
?>
//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, ' '));
}
<?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,
<?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
@wplokal
wplokal / select2-chained.js
Last active April 14, 2021 23:55
select2 ajax chained - wilayah indonesia
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){
<?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)
<?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