WordPress.org

Ready to get started?Download WordPress

Forums

Overriding Parent Theme Functions (1 post)

  1. Nos402
    Member
    Posted 1 year ago #

    OK, I've Googled and read tons of how to's on this, but obviously I am missing something, as I can't get it to work.

    I'm customizing the "the-vintage" theme and there are two functions I want to change.

    Basically, I want to change this:

    // Post meta data
    function vintage_post_meta() {?>
    <div class="comment-bubble"><?php if ( comments_open() ) : comments_popup_link('0', '1', '%', 'count'); else: echo '<span title="Comments are disabled" class="count">OFF</span>'; endif; ?></div>
    <div class="entry-date toggle">
        <div class="d font-1"><?php the_time('d') ?></div>
        <div class="m font-1"><?php the_time('M') ?></div>
        <div class="toggle-me">
        	<b>Posted:</b>
            <p><?php the_time('F j, Y l'); ?> at <?php the_time('g:i a'); ?></p>
        </div>
    </div><!--entry-date-->
    <?php edit_post_link('Edit this entry.', '', ''); ?>
    <div class="clear"></div>
    <?php if ( is_single() ):?>
    <div class="tags-cats">
    <?php
    /*$onchange = "onchange=\"document.location.href=this.options[this.selectedIndex].value;\"";
    echo "<select class='cats' $onchange>
    	<option class='title'>Categories</option>\n";
        foreach (get_the_category() as $category)  {
            echo "<option value=\"".get_category_link($category->term_id )."\">".ucwords($category->cat_name)."</option>\n";
        }
    echo "</select>";
    $tags = get_the_tags();
    if ($tags):
    echo "<select class='tags' $onchange>
    	<option class='title'>Tags</option>\n";
        foreach ($tags as $tag)  {
            echo "<option value=\"".get_tag_link($tag->term_id)."\">".ucwords($tag->name)."</option>\n";
        }
    echo "</select>";
    endif;*/
    ?>
    <p>
    <b>Categories:</b> <?php the_category(', '); ?>
    
    <?php the_tags('<b>Tags:</b> ', ', ', ''); ?>
    </p>
    
    </div><!--tags-cats-->
    <?php endif;
    } // end post_meta func
    // Prev-Next Navigation Links
    function vintage_navigation() {?>
    <div class="navigation">
    	<div class="alignleft"><?php next_posts_link('Older Posts') ?></div>
    	<div class="alignright"><?php previous_posts_link('Newer Posts') ?></div>
    </div><?php
    } // end func

    to this:

    // Post meta data
    function shenanigangsters_post_meta() {?>
    <div class="comment-bubble"><?php if ( comments_open() ) : comments_popup_link('0', '1', '%', 'count'); else: echo '<span title="Comments are disabled" class="count">OFF</span>'; endif; ?></div>
    <div class="entry-date toggle">
        <div class="d font-1"><?php the_time('d') ?></div>
        <div class="m font-1"><?php the_time('M') ?></div>
        <div class="toggle-me">
        	<b>Posted:</b>
            <p><?php the_time('F j, Y l'); ?> at <?php the_time('g:i a'); ?></p>
        </div>
    </div><!--entry-date-->
    <?php if ( is_single() ):?>
    
    <?php endif;
    } // end post_meta func
    
    // Prev-Next Navigation Links
    function shenanigangsters_navigation() {?>
    <div class="navigation">
    	<div class="alignleft"><?php next_post('%','Older Posts','no'); ?></div>
    	<div class="alignright"><?php previous_post('%','Newer Posts','no'); ?></div>
    </div><?php
    } // end func

    If I simply paste mine into a child functions.php, I get an error about the } just before //end func.

    In the tutorials I've read, it talks about deactivating the original functions and activating yours, but it says to find the "phase" by looking for an "add_action" after the functions. In the original functions.php there are no add_actions after those two functions. I am basically just fumbling my way around, since I'm not an actual PHP expert or anything. At the moment, I've just altered the original full functions.php file and all is working but I want to make my changes upgrade proof. For reference, here is the full original functions.php:

    <?php
    if ( function_exists('register_sidebar') ):
        register_sidebar(array(
    		'name' => 'Sidebar Widget Area',
    		'id' => 'sidebar-widget-area',
    		'description' => 'The sidebar widget area width: 213px' ,
    		'before_widget' => '<div class="widgetBlock">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="font-1">',
    		'after_title' => '<span></span></h3>',
        ));
    	register_sidebar( array(
    		'name' => 'Footer Widget Area 1' ,
    		'id' => 'footer-widget-area-1',
    		'description' => 'Note: Position "left" and width: 300px',
    		'before_widget' => '<div class="footer-widget">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="font-1">',
    		'after_title' => '</h3>',
    	) );
    	register_sidebar( array(
    		'name' => 'Footer Widget Area 2',
    		'id' => 'footer-widget-area-2',
    		'description' =>  'Note: Position "center" and width: 300px' ,
    		'before_widget' => '<div class="footer-widget center">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="font-1">',
    		'after_title' => '</h3>',
    	) );
    	register_sidebar( array(
    		'name' =>  'Footer Widget Area 3',
    		'id' => 'footer-widget-area-3',
    		'description' => 'Note: Position "right" and width: 300px' ,
    		'before_widget' => '<div class="footer-widget right">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="font-1">',
    		'after_title' => '</h3>',
    	) );
    endif;
    
    // Basic theme setup.
    function if_theme_setup() {
    	global $content_width;
    	if ( ! isset( $content_width ) ) $content_width = 660; //Set content width
    	// add_theme_support('post-formats',array('aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat'));
    	add_editor_style();
    	add_theme_support('automatic-feed-links');
    	add_theme_support('post-thumbnails');
    	set_post_thumbnail_size( 110, 110, true ); // Default size
    	// This theme uses wp_nav_menu() in one location.
    	register_nav_menus(array('primary' => 'Header Menu'));
    }
    add_action( 'after_setup_theme', 'if_theme_setup' );
    
    // Add a home link to wp_nav_menu
    function vintage_add_home_link($menuitems, $args) {
    	if('primary' == $args->theme_location) {
    		$home = '<li class="home"><a href="'. home_url() .'/"><strong>'. get_bloginfo('name') .'</strong></a></li>';
    		$menuitems = $home . $menuitems;
    	}
    return $menuitems;
    }
    add_filter( 'wp_nav_menu_items', 'vintage_add_home_link', 10, 2 );
    
    //Multi-level pages menu
    function vintage_page_menu() {
    	//wp_list_pages('depth=3&sort_column=menu_order&title_li=');
    	echo '<ul class="menu">';
    	?><li class="home"><a href="<?php echo home_url(); ?>/"><strong><?php bloginfo('name'); ?></strong></a></li><?php
    	wp_list_pages('sort_column=menu_order&title_li=&link_before=&link_after=<span></span>&depth=3');
    	echo '</ul>';
    } 
    
    // Scripts
    function vintage_enqueue_scripts() {
    	if (!is_admin()) {
    	  wp_deregister_script( 'jquery' );
    	  wp_register_script( 'jquery', 'http://code.jquery.com/jquery-latest.js');
    	  wp_enqueue_script( 'jquery' );
    	  wp_register_script('custom_script',
    	  get_template_directory_uri() . '/js.js');
    	  wp_enqueue_script('custom_script');
    	  wp_enqueue_style( 'theme-fonts', 'http://fonts.googleapis.com/css?family=Special+Elite', array(), false, 'screen' );
    	  if ( is_singular() && get_option( 'thread_comments' ) ) wp_enqueue_script( 'comment-reply' );
    	}
    }
    add_action('init', 'vintage_enqueue_scripts');
    
    // Tag Cloud Args
    function vintage_tag_cloud_filter($args = array()) {
    	$args = array(
    	'smallest'                  => 10,
    	'largest'                   => 10,
    	'unit'                      => 'pt',
    	'number'                    => 20,
    	'format'                    => 'list',
    	'separator'                 => "",
    	'orderby'                   => 'count',
    	'order'                     => 'DESC' );
     return $args;
    }
    add_filter('widget_tag_cloud_args', 'vintage_tag_cloud_filter', 90);
    
    // Print the post title
    function vintage_post_title() {
    if (is_single() or is_page()):
    ?>
      <h1><a class="font-1 post-title" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
    <?php  else:  ?>
      <div class="pin i secret"></div>
      <h2><a class="font-1 post-title" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php
    endif;
    if ( !get_the_title() and !is_single() ): ?><a href="<?php the_permalink() ?>" rel="bookmark" title="Permalink">&infin;</a><?php endif; ?>
    <?php
    } // end post title func
    
    // Post meta data
    function vintage_post_meta() {?>
    <div class="comment-bubble"><?php if ( comments_open() ) : comments_popup_link('0', '1', '%', 'count'); else: echo '<span title="Comments are disabled" class="count">OFF</span>'; endif; ?></div>
    <div class="entry-date toggle">
        <div class="d font-1"><?php the_time('d') ?></div>
        <div class="m font-1"><?php the_time('M') ?></div>
        <div class="toggle-me">
        	<b>Posted:</b>
            <p><?php the_time('F j, Y l'); ?> at <?php the_time('g:i a'); ?></p>
        </div>
    </div><!--entry-date-->
    <?php edit_post_link('Edit this entry.', '', ''); ?>
    <div class="clear"></div>
    <?php if ( is_single() ):?>
    <div class="tags-cats">
    <?php
    /*$onchange = "onchange=\"document.location.href=this.options[this.selectedIndex].value;\"";
    echo "<select class='cats' $onchange>
    	<option class='title'>Categories</option>\n";
        foreach (get_the_category() as $category)  {
            echo "<option value=\"".get_category_link($category->term_id )."\">".ucwords($category->cat_name)."</option>\n";
        }
    echo "</select>";
    $tags = get_the_tags();
    if ($tags):
    echo "<select class='tags' $onchange>
    	<option class='title'>Tags</option>\n";
        foreach ($tags as $tag)  {
            echo "<option value=\"".get_tag_link($tag->term_id)."\">".ucwords($tag->name)."</option>\n";
        }
    echo "</select>";
    endif;*/
    ?>
    <p>
    <b>Categories:</b> <?php the_category(', '); ?>
    
    <?php the_tags('<b>Tags:</b> ', ', ', ''); ?>
    </p>
    
    </div><!--tags-cats-->
    <?php endif;
    } // end post_meta func
    // Prev-Next Navigation Links
    function vintage_navigation() {?>
    <div class="navigation">
    	<div class="alignleft"><?php next_posts_link('Older Posts') ?></div>
    	<div class="alignright"><?php previous_posts_link('Newer Posts') ?></div>
    </div><?php
    } // end func
    
    // Sets the post excerpt length to 40 words.
    function vintage_excerpt_length( $length ) {
    	return 60;
    }
    add_filter( 'excerpt_length', 'vintage_excerpt_length' );
    
    // Returns a Continue Reading link for excerpts
    function vintage_continue_reading_link() {
    	return '<span class="more-link"><a href="'. esc_url( get_permalink() ) . '">' . __( '<span class="button">Continue reading &rarr;</span>', 'vintage' ) . '</a></span>';
    }
    
    // Replaces "[...]".
    function vintage_auto_excerpt_more( $more ) {
    	return ' &hellip;' . vintage_continue_reading_link();
    }
    add_filter( 'excerpt_more', 'vintage_auto_excerpt_more' );
    
    // Adds Continue Reading link to excerpts.
    function vintage_custom_excerpt_more( $output ) {
    	if ( has_excerpt() && ! is_attachment() ) {
    		$output .= vintage_continue_reading_link();
    	}
    	return $output;
    }
    add_filter( 'get_the_excerpt', 'vintage_custom_excerpt_more' );
    //
    function vintage_by() {
    	echo '<a href="http://www.alihan.com.tr/blog/"><img src="'.get_template_directory_uri().'/images/designer.png" alt="" /></a>';
    } 
    
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic