Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #9268
    ogutierrez
    Member

    Hello,

    I am using catch box (Public), and would like to know how I can add a custom function to functions.php? At the moment every time there is an update of the theme, I have to add the code back.

    The code is for google Adsense, which is call out inside a post. This is the my site,
    http://www.ogutierrezjr.com/blog/
    This is the function called out from the post
    [adsense float='center']
    This is the code that I am trying to add to the functions.php

    // **** Start of Google Addsence Function ****;
    // allowed parameter: 'left', 'center', 'right', 'none';
    // other entries will be treated as 'none';
    function add_adsense($atts) {
      extract(shortcode_atts(array(
      'float' => 'none',
      ), $atts));
    if( $float == 'left' ) $float = ' style=" float:left; margin: 10px 10px 5px 0; "';
    elseif( $float == 'center' ) $float = ' style=" display:block; margin: 10px auto; text-align:center; "';
    elseif( $float == 'right' ) $float = ' style=" float:right; margin: 10px 0 5px 10px; "';
    else $float = '';
    $ads = '<span class="adsense "'.$float.'>
    			<script type="text/javascript"><!--
    				google_ad_client = "ca-pub-4709087591608098";
    				/* main_post_add */
    				google_ad_slot = "2143366565";
    				google_ad_width = 468;
    				google_ad_height = 60;
    				//-->
    			</script>
    				<script type="text/javascript"
    				src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    			</script>
    </span>';
    return $ads;
    }
     
    add_shortcode('adsense', 'add_adsense');
    
    // **** End of Google Addsence Function ****;
    #9272
    Sakin
    Keymaster

    @ogutierrez: Don’t edit any core theme files. Then changed will be overwritten when you update the theme.

    The best way to add or edit any core file or functions is to build child theme. See the link below to understand Child Theme Development.
    http://codex.wordpress.org/Child_Themes
    http://wp.tutsplus.com/tutorials/theme-development/child-themes-basics-and-creating-child-themes-in-wordpress/

    #9273
    ogutierrez
    Member

    Thank you,

    I will look into the links you sent me. If I have any other questions I’ll post here. Thanks

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Adding a custom function to function.php’ is closed to new replies.