WordPress.org

Forums

Portfolio Press
Functions for child theme (11 posts)

  1. figure2
    Member
    Posted 3 years ago #

    I have created a child theme of Portfolio Press and have made quite a few changes to the appearance. One change I would like to make is to have the hover effect of the portfolio title overlay controlled by css instead of jquery. I copied the jquery folder into my child theme folder and deleted the hover script from the theme.js file. I then attempted to override the functions script that calls the js file with a new functions.php file in the child theme folder with the following script:

    if ( ! function_exists( 'wpt_portfolio_custom_posts_per_page' ) ) :
    
    function my_portfolio_custom_posts_per_page( $query ) {
    	global $wp_the_query;
    	if ( $wp_the_query === $query && !is_admin() && is_post_type_archive( 'portfolio' ) ) {
    		$query->set( 'posts_per_page', '42' );
    	}
    }
    add_action( 'pre_get_posts', 'my_portfolio_custom_posts_per_page' );
    
    function my_undo_hooks( $query ) {
    	 remove_filter( 'pre_get_posts', 'wpt_portfolio_custom_posts_per_page' );
    }
    add_action( 'after_setup_theme', 'my_undo_hooks' );
    
    endif;

    Unfortunately the child theme still wants to call the script from the parent folder. Can someone offer advice on how I can get this to work. My quick fix was to delete the hover script from the theme.js file in the parent folder.

    Thanks, Mark

    http://wordpress.org/extend/themes/portfolio-press/

  2. Devin Price
    Member
    Theme Author

    Posted 3 years ago #

    Not sure what that code above refers to.

    If you want to remove a script set by the parent theme, use:
    http://codex.wordpress.org/Function_Reference/wp_deregister_script

    The script you're looking to remove is loaded like this:

    wp_enqueue_script( 'themejs', get_template_directory_uri() . '/js/theme.js', array( 'jquery' ), false, true );
  3. figure2
    Member
    Posted 3 years ago #

    Devin, in the functions.php file of the parent folder the scripts are registered with a single function:

    /**
     * Loads the required javascript for the drop down menus and jquery effects
     * on portfolio items and post formats.
     */
    
    function portfoliopress_scripts() {
    	wp_enqueue_script( 'superfish', get_template_directory_uri() .'/js/superfish.js', array( 'jquery' ), false, true );
    	if ( !is_single() ) {
    		wp_enqueue_script( 'themejs', get_template_directory_uri() . '/js/theme.js', array( 'jquery' ), false, true );
    	}
    }
    
    add_action('wp_enqueue_scripts', 'portfoliopress_scripts');

    I thought it made sense to disable the "portfoliopress_scripts" function so I could replace it with my own version of the scripts.

    Mark

  4. Devin Price
    Member
    Theme Author

    Posted 3 years ago #

    Sure, you could do that if you want to re-enqueue superfish.

    Then just use remove_action in your child theme:

    remove_action('wp_enqueue_scripts', 'portfoliopress_scripts',100);
  5. figure2
    Member
    Posted 3 years ago #

    So here is what I have. It is still taking the theme.js from the parent directory.

    function my_deregister_parentTheme() {
    	wp_deregister_script( 'theme.js' );
    }
    
    add_action( 'wp_print_scripts', 'my_deregister_parentTheme', 100 );
    
    function bptArtTrail_script() {
    	if ( !is_single() ) {
    		wp_enqueue_script( 'themejs', get_template_directory_uri() . '/js/theme.js', array( 'jquery' ), false, true );
    	}
    }
    
    add_action('wp_enqueue_scripts', 'bptArtTrail_script');

    For now I have modified the theme.js file inside the parent folder. I have a modified copy of the theme.js file inside a js directory in my child theme folder. How do I get the theme to pull the theme.js content from the child folder?

    Mark

  6. Devin Price
    Member
    Theme Author

    Posted 3 years ago #

    In child theme:

    wp_deregister_script( 'themejs' );
    wp_enqueue_script( 'customthemejs', get_stylesheet_directory_uri() . '/js/customtheme.js', array( 'jquery' ), false, true );

    Assumes you change the name of the js file to customtheme.js in your child theme.

  7. figure2
    Member
    Posted 3 years ago #

    Thanks Devin but unfortunately it didn't work. As per your instructions,

    1. I changed the name of "theme.js" to "customtheme.js" in my child theme's js folder.
    2. I then replaced the code I had before with your code in my child theme's functions.php.
    3. The last step was to restore theme.js in the parent folder to its original state.

    As soon as I did that the portfolio item's hover behavior took on the parent theme's jquery behaviors.
    For now I have put my modified jquery code back into theme.js.

  8. Alain RONK
    Member
    Posted 3 years ago #

    Hello,

    I have long used the child theme with many mods in style.css and functions.php files that are complementary to those present in the parent theme. From this side, no problem ...

    But it is written everywhere that the other files included in the child theme (eg, footer.php, header.php, etc. ...) take precedence over files in the parent theme.

    What if the update of the parent theme among other concerns, the files in the child theme?
    It therefore receives more than the update?

    Am I mistaken or not?

    Thank you for your answers.
    Excuse me for my english

    Best regards
    Alain
    Website : http://www.modelisme-racer.fr/

  9. esmi
    Forum Moderator
    Posted 3 years ago #

    Please post your own topic. You are using a completely different themes.

  10. Alain RONK
    Member
    Posted 3 years ago #

    It's ok !
    Thank you

  11. figure2
    Member
    Posted 3 years ago #

    Alain, to answer your question, I put a copy of the Portfolio Press functions.php in my child theme folder so I could modify the functions I wanted. I, like you believed that the child theme's functions would take precedence over the parent theme but all it did was break the site. So until I have another solution, I will need to modify the parent theme's functions and jquery to get the results I want.

    Mark

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic