Home Forums Pure Theme Discussion & Support A better way of modifying content?

This topic is: resolved

This topic contains 5 replies, has 2 voices, and was last updated by  JM Knowles 4 years, 5 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2981

    JM Knowles
    Member
    Post count: 19

    Hi again. I am probably going to be modifying the content a bit. So I found the content.php file in the base directory. If I want to modify that I have to either modify the parent theme (bad but that is what I am doing) or should I be using filters in the function file? And if it is the latter if possible can you please give me an example of how I would do the following …. add some extra text above the menu as shown below? Thanks.

    if ( !function_exists('livingos_page_menu') ) {
    
    	function livingos_page_menu() {
    
    		// page menu
    
    			$content = '<nav id="page-menu" role="navigation"><span id="site_name">SOMETHING I WANT TO ADD</span>';
    
    			if ( has_nav_menu('pagemenu') ) {
    
    				$content .= wp_nav_menu( array( 'depth' => 1, 'echo' => false, 'theme_location' => 'pagemenu', 'menu_class' => 'page-menu' )) 

    ;

    #2987

    themeweaver
    Keymaster
    Post count: 730

    There are often more than one way to achieve things like this. But you are right – you should never edit code in the parent theme and absolutely never in the base folder.

    The best way is create a child theme and then all your edits will not interfere with upgrade to the theme.

    Many of the theme’s functions like those in content.php can be customised either by using a filterm (where exists) or by redefining the function in a child theme.

    So in this case you could create a new function in a child theme’s functions.php called livingos_page_menu() and this would override the parent function.

    Or, and probably the preferred way in this case is to use the filter since one exists:

    Add something like this to your child theme’s functions.php.

    function my_new_menu_content( $thecontent ){
    
        //appends a paragraph - a bit pointless but is just an example
        $thecontent .= '<p>Oh look a new paragrpah</p>';
       
       return $thecontent;
    }
    add_filter('livingos_page_menu','my_new_menu_content' );

    Your function just needs to manipulate the content produced by the original function and return it modified. You could add content before or after it.

    #2989

    JM Knowles
    Member
    Post count: 19

    Cool thanks Mr. Weaver.

    #2991

    JM Knowles
    Member
    Post count: 19

    I guess though if I want to modify widgets … like the show and twitter widgets I have no choice though but to edit the files in the main folder – is this correct?

    #2992

    themeweaver
    Keymaster
    Post count: 730

    Maybe, but there is a livingos_widgets_after_post filter in the show posts code. We will also be providing more hooks into the widgets in time too.

    Also if there are things that the widgets don’t do then let us know because we will always consider making improvements.

    #2993

    JM Knowles
    Member
    Post count: 19

    Good to know thanks. Yeah there are a few little things that I am adding but I am not sure how universal the demand is. You can see my work in progress (if you are curious) the front page of http://app-promo.com/beta/ In the widget areas of #second-content and #third-content you can see how the client wanted little icons in the titles that I manually added.

    By the way I love your themes. Just noticed I get a discount on my next theme …. cool! (I couldn’t tell how much though until I added to cart – 34.00 is a STEAL and I will definitely be picking another one up soon.)

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.