Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
Last active October 8, 2023 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finalwebsites/4b64b4f624af26bd106397a3f97fa854 to your computer and use it in GitHub Desktop.
Save finalwebsites/4b64b4f624af26bd106397a3f97fa854 to your computer and use it in GitHub Desktop.
Voorbeelden voor WordPress action en filter hooks
<?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>';
}
<?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>
';
}
<?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;
}
<?php
add_filter( 'ocean_single_related_posts', 'ctheme_related_posts_title' );
function ctheme_related_posts_title() {
return 'Deze blogposts wil je ook lezen';
}
<?php
add_filter( 'hello_elementor_page_title', 'ctheme_disable_page_title' );
function ctheme_disable_page_title( $return ) {
return false;
}
<?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;
}
<?php
remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
add_action( 'woocommerce_after_main_content', 'woocommerce_taxonomy_archive_description', 100 );
<?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