Last active
October 8, 2023 14:51
-
-
Save finalwebsites/4b64b4f624af26bd106397a3f97fa854 to your computer and use it in GitHub Desktop.
Voorbeelden voor WordPress action en filter hooks
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 | |
add_action( 'storefront_header', 'ctheme_storefront_header_content', 40 ); | |
function ctheme_storefront_header_content() { | |
echo ' | |
<div class="header-usp"> | |
Gratis verzending - Voor 14 uur besteld? Volgende dag bezorgt. | |
</div>'; | |
} |
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 | |
add_action( 'wp_head', 'ctheme_add_content_to_head' ); | |
function ctheme_add_content_to_head(){ | |
echo ' | |
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXX-XX"></script> | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
function gtag(){dataLayer.push(arguments);} | |
gtag(\'js\', new Date()); | |
gtag(\'config\', \'UA-XXXXXX-XX\', {"anonymize_ip":true}); | |
</script> | |
'; | |
} |
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 | |
add_filter('the_title', 'ctheme_new_title', 10, 2); | |
function ctheme_new_title($title, $id) { | |
if ('review' == get_post_type($id)) $title = $title.'<span class="label-tag">Review</span>; | |
return $title; | |
} |
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 | |
add_filter( 'ocean_single_related_posts', 'ctheme_related_posts_title' ); | |
function ctheme_related_posts_title() { | |
return 'Deze blogposts wil je ook lezen'; | |
} |
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 | |
add_filter( 'hello_elementor_page_title', 'ctheme_disable_page_title' ); | |
function ctheme_disable_page_title( $return ) { | |
return false; | |
} |
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 | |
add_filter('pre_get_posts','ctheme_search_filter'); | |
function ctheme_search_filter($query) { | |
if (!is_admin() && $query->is_main_query()) { | |
if ($query->is_search) { | |
$query->set('post__not_in', array(123, 110, 5, 12)); | |
} | |
} | |
return $query; | |
} |
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 | |
remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 ); | |
add_action( 'woocommerce_after_main_content', 'woocommerce_taxonomy_archive_description', 100 ); |
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 | |
add_action( 'add_attachment', 'ctheme_set_image_alt_after_upload' ); | |
function ctheme_set_image_alt_after_upload( $post_ID ) { | |
if ( wp_attachment_is_image( $post_ID ) ) { | |
$post = get_post( $post_ID ); | |
update_post_meta( $post_ID, '_wp_attachment_image_alt', $post->post_title ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment