Skip to content

Instantly share code, notes, and snippets.

View dgoze's full-sized avatar
💭
I may be slow to respond.

Daniel dgoze

💭
I may be slow to respond.
View GitHub Profile
<?php
add_filter( 'post_type_archive_link', 'fix_post_type_archive_link', 10, 2 );
function fix_post_type_archive_link( $link, $post_type ) {
if($post_type == 'scripts'){
$link = str_replace('/%some-slug%', '', $link);
}
return $link;
}
@dgoze
dgoze / Post_permalink_with_taxonomy_slug.php
Created August 15, 2024 23:25 — forked from vovadocent/Post_permalink_with_taxonomy_slug.php
CPT post permalink with taxonomy slug
<?php
/*
'rewrite' => array('slug' => 'scripts/%custom-taxonomy%'), // register post type arg 'rewrite'
*/
add_filter('post_type_link', 'change_cpt_post_permalink', 99, 3);
function change_cpt_post_permalink($permalink, $post_id) {
if (strpos($permalink, '%custom-taxonomy%') === FALSE)
return $permalink;
$post = get_post($post_id);
if (!$post)
@dgoze
dgoze / wp_modify_admin_user_column.php
Created August 15, 2024 23:25 — forked from vovadocent/wp_modify_admin_user_column.php
Modify and add Admin User Column
<?php
add_action('manage_users_columns','kjl_modify_user_columns');
function kjl_modify_user_columns($column_headers) {
//unset($column_headers['posts']);
$column_headers['status'] = 'Status';
return $column_headers;
}
function kjl_user_posts_count_column_content($value, $column_name, $user_id) {
//$user = get_userdata($user_id);
@dgoze
dgoze / template-functions.php (for taxonomy)
Created August 15, 2024 23:24 — forked from woraperth/template-functions.php (for taxonomy)
[WordPress] Add ACF Admin Column to taxonomy (In this example, taxonomy name = product_category & ACF column name = english_name)
// Add ACF Columns
function add_new_product_cat_column($column) {
$column['english_name'] = 'English Name';
return $column;
}
add_filter('manage_edit-product_category_columns', 'add_new_product_cat_column');
function add_new_product_cat_admin_column_show_value( $content, $column_name, $term_id ) {
@dgoze
dgoze / wp-get-youtube-thumb.php
Created August 15, 2024 23:23 — forked from woraperth/wp-get-youtube-thumb.php
[WordPress] Get Youtube video thumbnail from URL & Set as Featured Image
// Get Youtube URL
$yturl = 'https://www.youtube.com/watch?v=HhAKNSsb4t4';
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $yturl, $matches);
$video_id = $matches[1];
// Get Thumbnail
$file_headers = get_headers( 'http://img.youtube.com/vi/' . $video_id . '/maxresdefault.jpg' );
$is_404 = $file_headers[0] == 'HTTP/1.0 404 Not Found' || false !== strpos( $file_headers[0], '404 Not Found' );
$video_thumbnail_url = $is_404 ? 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' : 'http://img.youtube.com/vi/' . $video_id . '/hqdefault.jpg';
<?php
/**
* For debug
* show template file name
* ---------------------------------------------------------*/
function show_template() {
global $template;
echo basename( $template );
}
<?php
add_filter('request', 'hwk_post_type_toplevel_request', 1, 1);
function hwk_post_type_toplevel_request($query){
$post_type = 'portfolio';
if(isset($query[$post_type]) && isset($query['post_type']) && $query['post_type'] === 'portfolio')
return $query;
@dgoze
dgoze / get_field_from_block.php
Created August 2, 2024 00:02 — forked from yesnosurely/get_field_from_block.php
get acf field from gutenberg block [php, wp, acf, wordpress]
<?php
function get_field_from_block($post_id, $block_name, $field_name){
$block_name = 'acf/' . $block_name;
$post = get_post($post_id);
if ( has_blocks( $post->post_content ) ) {
$blocks = parse_blocks( $post->post_content );
foreach ($blocks as $block){
if ($block['attrs']['name'] == $block_name){
$data = $block['attrs']['data'][$field_name];
break;
@dgoze
dgoze / image_bg_color_nav_menu_item_ACF.php
Created August 1, 2024 23:48 — forked from vovadocent/image_bg_color_nav_menu_item_ACF.php
Add background-image or background-color to nav menu item using ACF
<?php
//add background-image or background-color to nav menu item using ACF
add_filter('wp_nav_menu_items', 'new_nav_menu_items', 10, 2);
function new_nav_menu_items($items, $args) {
preg_match_all('/menu-item-([0-9]{1,10})"/ ', $items, $matches);
if (isset($matches[0]) && isset($matches[1])) {
foreach ($matches[0] as $k => $repl) {
$post_id = $matches[1][$k];