Skip to content

Instantly share code, notes, and snippets.

View hmowais's full-sized avatar
🎯
Focusing

HM Owais hmowais

🎯
Focusing
  • Karachi, Pakistan
View GitHub Profile
@hmowais
hmowais / functions.php
Created January 6, 2022 05:44
Show Custom Post Types in Gravity Form Select Field
<?php
/* Show Custom Post Types in Gravity Form Select Field */
add_filter( 'gform_pre_render_2', 'populate_cpt_titles' );
add_filter( 'gform_pre_validation_2', 'populate_cpt_titles' );
add_filter( 'gform_pre_submission_filter_2', 'populate_cpt_titles' );
add_filter( 'gform_admin_pre_render_2', 'populate_cpt_titles' );
function populate_cpt_titles( $form ) {
foreach ( $form['fields'] as &$field ) {
if ( $field->type != 'select' || strpos( $field->cssClass, 'populate_cpt_titles' ) === false ) {
continue;
@hmowais
hmowais / functions.php
Last active January 3, 2022 07:03
Custom Post Types & Taxonomies Function Extended
<?php
/* Register CPT */
function cwptheme_post_type() {
$post_types_arr = array( 'Slider', 'Testimonial', 'Our Projects', 'Service');
foreach( $post_types_arr as $post_type_a){
$labels = array(
'name' => __( $post_type_a ),
@hmowais
hmowais / custom.js
Created December 17, 2021 13:58
Move Element on Scroll
var rect = $('#wrapper')[0].getBoundingClientRect();
var mouse = {x: 0, y: 0, moved: false};
$("#wrapper").mousemove(function(e) {
mouse.moved = true;
mouse.x = e.clientX - rect.left;
mouse.y = e.clientY - rect.top;
});
// Ticker event will be called on every frame
@hmowais
hmowais / functions.php
Created December 17, 2021 07:55
Replace Current Menu on Specific Page Template
add_filter('wp_nav_menu_args', 'show_correct_main_menu');
function show_correct_main_menu($args) {
if ( is_page_template( 'haspoa-page.php' ) ) {
if ( $args['menu'] = '33' ) {
$args['menu'] = '71';
}
}
return $args;
}
@hmowais
hmowais / functions.php
Created December 14, 2021 06:44
Add Custom Field in Post
<?php
/**
* Add service custom fields
*/
function add_service_meta_boxes() {
add_meta_box("service_contact_meta", "Design Numbers", "add_contact_details_service_meta_box", "services", "normal", "low");
}
function add_contact_details_service_meta_box() {
global $post;
@hmowais
hmowais / functions.php
Created December 13, 2021 06:51
Show Only Parent Category of Custom Post Types
<?php
// taxonomy of custom post type = resources_category
$terms = get_the_terms( $post->ID, 'resources_category' );
if( $terms ){
foreach( $terms as $term ){
if( $term->parent == 0 )
echo $term->term_id;
}
}
@hmowais
hmowais / functions.php
Created December 9, 2021 13:36
Swiper Slider
/* Custom Scripts */
function swiper_slider() { ?>
<script>
jQuery( document ).ready(function($) {
$( ".expertise .swiper-slide" ).wrapAll( "<div class='swiper-wrapper' />");
$( ".expertise .swiper-wrapper" ).wrapAll( "<div class='swiper-container' />");
$( ".expertise .swiper-container" ).after( "<div class='swiper-button-next'></div>" );
$( ".expertise .swiper-container" ).after( "<div class='swiper-button-prev'></div>" );
@hmowais
hmowais / functions.php
Created December 8, 2021 13:13
Register CPT
<?php
/* Register Resource CPT */
add_action('init', 'create_resources_category_hierarchical_taxonomy', 0);
function create_resources_category_hierarchical_taxonomy() {
$labels = array(
'name' => _x('Add Resource Category', 'taxonomy general name') ,
'singular_name' => _x('Resource Category', 'taxonomy singular name') ,
'search_items' => __('Search Resource Category') ,
@hmowais
hmowais / function.php
Created October 15, 2021 13:24
Blog URL issue For Custom Post Types
<?php
// $args = array(
// 'public' => true,
// 'labels' => $labels,
// 'menu_position' => 20,
// 'menu_icon' => 'dashicons-welcome-write-blog',
// 'supports' => array(
// 'title',
// '',
@hmowais
hmowais / function.php
Created October 15, 2021 12:43
change post author = admin
<?php
// change post author = admin
function replace_author( $data , $postarr )
{
$data['post_author'] = 1;
return $data;
}
add_filter('wp_insert_post_data' , 'replace_author' , '99', 2);