Skip to content

Instantly share code, notes, and snippets.

@fahdi
Created April 20, 2022 11:15
Show Gist options
  • Save fahdi/b4d2816142531bedd70ff1919d0a34f3 to your computer and use it in GitHub Desktop.
Save fahdi/b4d2816142531bedd70ff1919d0a34f3 to your computer and use it in GitHub Desktop.
Examples for WP filter
<?php
/*
Plugin Name: Filter the content to remove ADULTKEYWORD. This is an example plugin
*/
add_filter('the_content', 'fm_filter_the_main_loop', 1);
function fm_filter_the_main_loop($content)
{
// Check if we're inside the main loop in a single Post.
if (is_singular() && in_the_loop() && is_main_query()) {
$content = str_replace('ADULTKEYWORD', '...', $content);
}
return $content;
}
add_filter('the_title', 'fm_format_title', 1);
function fm_format_title($title)
{
if (is_singular() || is_front_page()) {
$title = $title." - by ". get_the_author();
}
return $title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment