• Resolved rebah

    (@rebah)


    Hey,

    I’m trying to add some code the the function.php of my child theme, but I’m not sure how to do it the right way as everytime I try, the website crashes.

    I believe this code previously worked when I wasn’t using a child theme. I only noticed the other day that the custom code was removed during an update, so that’s why I now want to add it to the child theme’s function.php

    I want to hide a category so I add:

    action set_category_widget_parameters($args) {
    $args[‘exclude’] = ‘154’;
    return $args;
    }
    add_filter(‘widget_categories_args’,’set_category_widget_parameters’);

    This is the function.php of the child theme:

    <?php
    /* —————————————————————————-
    Newspaper 7 Child theme – Please do not use this child theme with older versions of Newspaper Theme

    What can be overwritten via the child theme:
    – everything from /parts folder
    – all the loops (loop.php loop-single-1.php) etc

    – the rest of the theme has to be modified via the theme api:
    https://forum.tagdiv.com/the-theme-api/

    */

    /* —————————————————————————-
    add the parent style + style.css from this folder
    */
    add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’, 1001);
    function theme_enqueue_styles() {
    wp_enqueue_style(‘td-theme’, get_template_directory_uri() . ‘/style.css’, ”, ‘6.1c’, ‘all’ );
    wp_enqueue_style(‘td-theme-child’, get_stylesheet_directory_uri() . ‘/style.css’, array(‘td-theme’), ‘6.1c’, ‘all’ );

    }

    Where do I add it or is there something wrong with the code?

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Hi rebah

    Please post code & markup between backticks (`) or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.

    function set_category_widget_parameters($args) {
    $args[‘exclude’] = ‘154’;
    return $args;
    }
    add_filter(‘widget_categories_args’,’set_category_widget_parameters’);

    action needed to be function

    I crash my site everytime too

    function add_parameter_to_url($content) {
    	$transaction_id="";
    	if(!empty($_GET['transaction_id'])) $transaction_id=$_GET['transaction_id'];
    
    	$aff_sub="";
    	if(!empty($_GET['aff_sub'])) $aff_sub=$_GET['aff_sub'];
    
    	$aff_sub2="";
    	if(!empty($_GET['aff_sub2'])) $aff_sub2=$_GET['aff_sub2'];
    
    	$source="";
    	if(!empty($_GET['source'])) $source=$_GET['source'];
    
    	$affiliate_id="";
    	if(!empty($_GET['affiliate_id'])) $source=$_GET['affiliate_id'];
    
    	$content=str_replace('{transaction_id}',$transaction_id,$content);
    	$content=str_replace('{aff_sub}',$aff_sub,$content);
    	$content=str_replace('{aff_sub2}',$aff_sub2,$content);
    	$content=str_replace('{source}',$source,$content);
    $content=str_replace('{affiliate_id}',$affiliate_id,$content);
    	//$content="testing";
    	return $content;
    }
    
    add_filter( 'the_content', 'add_parameter_to_url',20 );

    `

    Thread Starter rebah

    (@rebah)

    Ah ok tnx keesie I will use code from now on.

    Jacob, I added the code now without the site crashing, so that’s progress. But the code doesn’t do what I want it to do. The ‘Featured’ category (ID 154) is still showing in the footer widget. Any clue on a next step?

    This is the code is my child’s function.php now.

    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 1001);
    function theme_enqueue_styles() {
        wp_enqueue_style('td-theme', get_template_directory_uri() . '/style.css', '', '6.1c', 'all' );
        wp_enqueue_style('td-theme-child', get_stylesheet_directory_uri() . '/style.css', array('td-theme'), '6.1c', 'all' );
    
    function set_category_widget_parameters($args) {
    $args[‘exclude’] = ‘154’;
    return $args;
    }
    add_filter(‘widget_categories_args’,’set_category_widget_parameters’);
    }

    imho, your new code should be outside of the ‘theme_enqueue_scripts’ function;
    also, your code has some invalid single quote characters, possibly from copy/paste of the code.
    the single quotes have to be just simply '

    corrected code (untested):

    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 1001);
    function theme_enqueue_styles() {
        wp_enqueue_style('td-theme', get_template_directory_uri() . '/style.css', '', '6.1c', 'all' );
        wp_enqueue_style('td-theme-child', get_stylesheet_directory_uri() . '/style.css', array('td-theme'), '6.1c', 'all' );
    }
    
    function set_category_widget_parameters($args) {
    $args['exclude'] = '154';
    return $args;
    }
    add_filter('widget_categories_args','set_category_widget_parameters');
    Thread Starter rebah

    (@rebah)

    That did the trick. Great. Thanks a lot!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add code to function.php’ is closed to new replies.