Skip to content

Instantly share code, notes, and snippets.

@wpgaurav
Last active October 16, 2020 09:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpgaurav/d8f92da320e713bc0f3c7225588f970f to your computer and use it in GitHub Desktop.
Save wpgaurav/d8f92da320e713bc0f3c7225588f970f to your computer and use it in GitHub Desktop.
Marketers Delight Hooks
<?php
// Display Custom Excerpt below the headline on single posts.
function excerpt_single_post() {
if ( is_singular( 'post' ) && has_excerpt() ) {
the_excerpt();
}
}
add_action ('md_hook_after_headline', 'excerpt_single_post');
?>
<?php
// Add Search form next to logo. change 10 to other values to displace positions.
function add_search_form_header(){?>
<?php echo '<div class="csearch">';
get_search_form();
echo '</div>';
?>
<?php }
add_action ('md_hook_header', 'add_search_form_header', 10); ?>
<?php
// Remove [...] from archive excerpts
function new_excerpt_more($more) {
global $post;
remove_filter('excerpt_more', 'new_excerpt_more');
return ' ';
}
add_filter('excerpt_more','new_excerpt_more', 330);
?>
<?php
// Move main menu to the top of the page, i.e., above the logo and primary menu
remove_action( 'md_hook_before_content_box', 'md_main_menu', 2 );
function main_menu_hook() {
if ( md_has_main_menu() )
md_template( 'menus/main-menu' );
}
add_action('md_hook_before_html', 'main_menu_hook');
?>
<?php
// Add a custom button in primary menu
function trigger_hook() {?>
<a href="/contact/" itemprop="url" style="background:#c0392b; color:#fff; padding:8px 12px; margin-left:12px;"><span itemprop="name"><i class="md-icon-mail-alt"></i></span></a>
<?php }
add_action('md_hook_header_triggers', 'trigger_hook');
?>
<?php
// Make Footer Widgets 4 Columns instead of 3.
function md_child_theme_footer_columns() {
return array( 1, 2, 3, 4 );
}
add_filter( 'md_filter_footer_columns', 'md_child_theme_footer_columns' );?>
<?php
// Preload MD Icon font to boost page speed.
add_action('wp_head', 'add_mdicon_preload');
function add_mdicon_preload(){?>
<link rel="preload" href="/wp-content/themes/marketers-delight/lib/assets/icons/md.woff" as="font" crossorigin="anonymous" />
<?php }
?>
<?php
// Add RankMath Breadcrumbs above post title
function rm_bc() {
if (is_singular('post')){ ?>
<div class="byline content-inner">
<?php if (function_exists('rank_math_the_breadcrumbs')) rank_math_the_breadcrumbs(); ?>
</div>
<?php }
}
add_action('md_hook_before_headline', 'rm_bc', 20);
?>
<?php
// Set Marketers Delight as AMP Reader Theme. Futher optimization maybe required.
add_filter( 'amp_reader_themes', function ( $reader_themes ) {
$reader_themes[] = [
'name' => 'Marketers Delight',
'slug' => 'marketers-delight',
'preview_url' => 'https://marketersdelight.com/demo',
'screenshot_url' => '/wp-content/themes/marketers-delight/screenshot.png',
'homepage' => 'https://marketersdelight.com',
'description' => 'Marketers Delight is a powerful content driven WP theme',
];
$reader_themes[] = [
'name' => 'Marketers Delight Child',
'slug' => 'md-child',
'preview_url' => 'https://marketersdelight.com/demo',
'screenshot_url' => '/wp-content/themes/marketers-delight/screenshot.png',
'homepage' => 'https://marketersdelight.com',
'description' => 'Marketers Delight is a powerful content driven WP theme',
];
return $reader_themes;
} ); ?>
<?php function author_bio_hook(){
if (is_singular('post')) {?>
<?php
// To be used with Advanced Custom Fields Plugin, I have set the field ID to display_author_bio and that's a YES/NO checklist
if ( get_field( 'display_author_bio' ) ): ?>
<div id="author-bio" class="author-box">
<div class="inner">
<div class="author-avatar"><?php echo get_avatar( get_the_author_meta( 'ID' ), 60 ); ?></div>
<div id="author-details">
<h4><?php esc_html_e( 'This article was written by ', 'text_domain' ); ?><?php the_author_meta( 'display_name' ); ?></h4>
<p class="author-desc"><?php the_author_description(); ?></p>
</div><!-- #author-details -->
</div>
</div>
<?php else: ?>
<br>
<?php endif;
}
}
add_action('md_hook_content_item', 'author_bio_hook', 41); ?>
@wpgaurav
Copy link
Author

wpgaurav commented Sep 7, 2020

If you want to improve table styling, you can use (and customize according to your needs) this code:

table{border-collapse:collapse;border-spacing:0;empty-cells:show;border:1px solid #cbcbcb}

table figcaption{color:#000;padding:1em 0;text-align:center}
table td,table th{border-left:1px solid #cbcbcb;border-width:0 0 0 1px;margin:0;overflow:visible;padding:.5em 1em} table thead{background-color:#c0392b;color:#fff;vertical-align:middle} table tr:nth-child(2n-1) td{background-color:#f2f2f2} table td{border-bottom:1px solid #cbcbcb} table tbody>tr:last-child>td{border-bottom-width:0}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment