If you are using Genesis Theme Framework and would like to display Google Adsense or any advertisement code after the first post on the homepage, archives, and search results page, add the code below to the child theme’s functions.php file.
add_action('genesis_after_post', 'aycchildthemes_ad_after_first_post');
function aycchildthemes_ad_after_first_post() {
global $loop_counter;
if (!is_singular() && $loop_counter == 0) { ?>
ADD YOUR GOOGLE ADSENSE CODE HERE
<?php }
}
The code above which you add should be placed anywhere after this:
require_once(TEMPLATEPATH.'/lib/init.php');
And before the following closing code (if it exists):
?>
That’s it. Let me know your experience after using this snippet. Also please share if you have tricks complete this kinda job.
This is a simple task if you use the built in is_page() conditional tag in WordPress and use one of the Genesis structural action hooks. We’ll be using the genesis_before_sidebar_widget_area action hook in this example.
<?php
// Add additional sidebar content to the book page
add_action('genesis_before_sidebar_widget_area', 'child_genesis_sidebar');
function child_genesis_sidebar() {
if ( is_page('__SPECIFIC-PAGE-ID-OR-TITLE__')) { ?>
<your-content-code>
<?php
}
}
?>
There’s a lot of small code snippets I use often. This is where I’ll collect them. If you have any quick tips, feel free to share in the comments.
Force a page layout
This is very useful for ensuring custom pages you build for a client aren’t broken by them changing the page layout (ex: home page). Or, changing the page layout to something other than the default on archive pages (ex: category). The example below is to set the category page to Sidebar-Content-Sidebar.
// Force layout on category
add_filter('genesis_pre_get_option_site_layout', 'child_category_layout');
function child_category_layout($opt) {
if ( is_category() )
$opt = 'sidebar-content-sidebar';
return $opt;
}
Set default page layout
// Register default site layout option
genesis_set_default_layout( 'full-width-content' );
Setup the child theme
This is what I include at the top of my functions.php file in my child themes. Any time below you see an add_action or add_filter, that part goes in the setup function, and the function itself goes after the setup function.
// Start the engine
require_once(TEMPLATEPATH.'/lib/init.php');
// Setup the child theme
add_action('after_setup_theme','child_child_theme_setup');
function child_child_theme_setup() {
// ** Backend **
// Remove Purchase Themes menu link from dashboard
remove_theme_support('genesis-purchase-menu');
// ** Frontend **
}
Unregister unused page layouts
// Unregister other site layouts
genesis_unregister_layout( 'content-sidebar' );
genesis_unregister_layout( 'sidebar-content' );
genesis_unregister_layout( 'content-sidebar-sidebar' );
genesis_unregister_layout( 'sidebar-sidebar-content' );
genesis_unregister_layout( 'sidebar-content-sidebar' );
Add Image Sizes
This adds an image size named ‘feature’ with a fixed size of 600×250. See Mark Jaquith’s post for details.
add_image_size('feature', 600, 250, true);
Modify Post Info
Shortcode Reference
add_filter('genesis_post_info', 'child_post_info_filter');
function child_post_info_filter($post_info) {
$post_info = '[ post_date ] by [ post_author_posts_link ] at [ post_time ] [ post_comments ] [ post_edit ]';
return $post_info;
}
Remove Post Info
remove_action('genesis_before_post_content', 'genesis_post_info');
Modify Post Meta
add_filter('genesis_post_meta', 'child_post_meta_filter');
function child_post_meta_filter($post_meta) {
$post_meta = '[ post_categories ] Tagged with [ post_tags ]';
return $post_meta;
}</code>
<strong>Remove Post Meta</strong>
<code>remove_action('genesis_after_post_content', 'genesis_post_meta');
Change Excerpt More text […]
function child_excerpt_more($more) {
return '[.....]';
}
add_filter('excerpt_more', 'child_excerpt_more');
Remove Footer
remove_action('genesis_footer','genesis_do_footer');
Remove Footer and Footer Markup
// Remove Footer
remove_action('genesis_footer', 'genesis_do_footer');
remove_action('genesis_footer', 'genesis_footer_markup_open', 5);
remove_action('genesis_footer', 'genesis_footer_markup_close', 15);
Customize the Search Form text
add_filter('genesis_search_button_text', 'child_custom_search_button_text');
function child_custom_search_button_text($text) {
return esc_attr('');
}
Remove Breadcrumbs
add_filter('genesis_breadcrumb_args', 'child_custom_breadcrumb_args');
function child_custom_breadcrumb_args($args) {
$args['sep'] = ' > ';
$args['labels']['prefix'] = '';
return $args;
}
Customize the Site Title (in #header)
This is useful if you want to use the default site title (Settings > Title) but style different elements of it differently. This specific code searches for “of” in the site title, and changes it to <em>of</em>.
// Customize the site title
add_filter('genesis_seo_title','child_customize_site_title', 10, 3);
function child_customize_site_title($title, $inside, $wrap) {
$custom = str_replace("of", "<em>of</em>", $title);
return $custom;
}
Customize the Site Description (in #header)
add_filter('genesis_seo_description','child_customize_site_description', 10, 3);
function child_customize_site_description($description, $inside, $wrap) {
$custom = str_replace("Redefining", "<strong>Redefining</strong>", $description);
return $custom;
}
Remove the Post Title
// Remove Post Title
remove_action('genesis_post_title','genesis_do_post_title');
Remove Page Titles
/** Remove page titles */
add_action( 'get_header', 'child_remove_page_titles' );
function child_remove_page_titles() {
if ( is_page() && ! is_page_template( 'page_blog.php' ) )
remove_action( 'genesis_post_title', 'genesis_do_post_title' );
}
Display Description of Menu Items
To add a description to a menu item, go to Appearances > Menus. At the top right click “Screen Options”, then check “Description”. Now you can click the dropdown arrow next to menu items and add a description. The below code will make it visible on the site.
// Display Description of Menu Items
add_filter( 'walker_nav_menu_start_el', 'child_add_description', 10, 2 );
function child_add_description( $item_output, $item ) {
$description = __( $item->post_content );
return preg_replace( '/(<a.*?>[^<]*?)</', '$1' . '<span >' . $description . '</span></', $item_output);
}
Register a Sidebar
genesis_register_sidebar(array(
'name'=>'Homepage Widgets',
'id' => 'homepage-widgets',
'description' => 'This shows up at the bottom of the homepage.',
));
Unregister a Sidebar
unregister_sidebar('sidebar-alt');
Customize Read More Link
// Customize Read More Link
add_filter( 'excerpt_more', 'child_more_link' );
add_filter( 'get_the_content_more_link', 'child_more_link' );
add_filter( 'the_content_more_link', 'child_more_link' );
function child_more_link($more_link, $more_link_text) {
return sprintf('%s', get_permalink(), 'Read More');
}
WEB DESIGN & MARKETING DHAKA
AREUCONNECTED is a Dhaka-based website design and digital marketing agency, with clients all around the world.
Our primary goal is to support small and medium-sized enterprises in their expansion by utilizing cutting-edge design concepts and technologies.
Our aim is to offer our clients the best solutions possible in the areas of web design & development, digital marketing, e-commerce, SEO, and branding.
Latest Articles
- The Art of the Backlink: Boosting Credibility and Ranking HigherMay 19, 2024 - 7:06 am
- Web Design Mistakes Every Designer Should Stay Away FromOctober 10, 2023 - 9:18 am
- 12 Design Tweaks to Improve Sales on Your E-commerce SiteOctober 5, 2023 - 2:11 am
Legal Docs
Get in Touch
- info@areuconnected.com
- www.areuconnected.com
- 13/11/B Meradia Ansarbag, Khilgaon, Dhaka 1219, Bangladesh