Clearing out the functions.php and saving parts

Hey all. I just snagged the Unlimited Pro license and am cleaning out my Pro Child functions.php from the tangle of bits of code I gathered over the years from here :slight_smile:

I’m not a .php expert (yet). Would someone please look at this code and show me -

a) What a CLEAN, unadorned child functions.php looks like
b) How to keep the functions that
b1) Adds the social sharing and subscribe at the bottom of posts
b2) Adds the Author Box at the bottom of posts

UPDATE - Whoa. I didn’t realize this post would parse the code out in one long thing that’s got to be a hassle to read. Is there a way to make it more readable for you all at ‘X’?

(I intentionally put this update above the text just to make it easier on you if I could)

here’s the code -->

<?php

// =============================================================================
// FUNCTIONS.PHP
// -----------------------------------------------------------------------------
// Overwrite or add your own custom functions to Pro in this file.
// =============================================================================

// =============================================================================
// TABLE OF CONTENTS
// -----------------------------------------------------------------------------
//   01. Enqueue Parent Stylesheet
//   02. Additional Functions
// =============================================================================

// Enqueue Parent Stylesheet
// =============================================================================

add_filter( 'x_enqueue_parent_stylesheet', '__return_true' );



// Additional Functions
// =============================================================================


// Add Social Sharing and Link to Donations Page at bottom of all posts


add_action( 'x_before_the_content_end', 'x_print_social', 999);

function x_print_social() {

    if ( is_singular('post') ) {


        echo do_shortcode('[share title="Share the Magick!" facebook="true" google_plus="true" linkedin="true" pinterest="true" reddit="true"]');
        echo '<p style="text-align: center;"><a href="https://intothemythica.com/subscribe//">LIKE THIS ARTICLE? WANT TO HELP CHANGE THE WORLD? CLICK TO JOIN THE MYTHICA!</a>';


    }

}


// Add revolution slider beneath categories for from the quest

// Add Author at bottom of all posts

add_action( 'x_before_the_content_end', 'x_post_category_slider', 998);
function x_post_category_slider () {

    if ( is_singular('post') ) {

        $category = get_the_category( get_the_ID() );

        $slider = "";

        if ( count( $category ) > 0 ) {

            switch ( $category[0]->term_id  ) {
                case 634: $slider = '[rev_slider alias="ftq-yeshualucis"]'; break;
                case 663: $slider = '[rev_slider alias="FTQ-peterfae"]'; break;
            }

            echo do_shortcode( $slider );
        }

        $author_id =  get_the_author_meta('ID');  
        echo do_shortcode('[author title="About the Author" author_id="'.$author_id.'"]');


    }

}








function redirect_user() {
if( is_user_logged_in() && is_home() || is_user_logged_in() && is_front_page() ) {
wp_redirect( 'https://www.intothemythica.com/worlds' );
exit;
}
}
add_action('init', 'redirect_user');




// Add Gutenberg editor to Zoom Timeline post

add_action( 'init', 'myprefix_cpt_init' );
function myprefix_cpt_init() {
 
    $labels = array(
        // not revelant for this article
    );
 
    $args = array(
        'labels'             => $labels,
        'description'        => __( 'Description.', 'textdomain' ),
        'public'             => true,        
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
    );
 
    register_post_type( 'mycpt', $args );
    
}



// Add file size list to media listing 

add_filter( 'manage_media_columns', 'sk_media_columns_filesize' );
/**
 * Filter the Media list table columns to add a File Size column.
 *
 * @param array $posts_columns Existing array of columns displayed in the Media list table.
 * @return array Amended array of columns to be displayed in the Media list table.
 */
function sk_media_columns_filesize( $posts_columns ) {
    $posts_columns['filesize'] = __( 'File Size', 'my-theme-text-domain' );

    return $posts_columns;
}

add_action( 'manage_media_custom_column', 'sk_media_custom_column_filesize', 10, 2 );
/**
 * Display File Size custom column in the Media list table.
 *
 * @param string $column_name Name of the custom column.
 * @param int    $post_id Current Attachment ID.
 */
function sk_media_custom_column_filesize( $column_name, $post_id ) {
    if ( 'filesize' !== $column_name ) {
        return;
    }

    $bytes = filesize( get_attached_file( $post_id ) );

    echo size_format( $bytes, 2 );
}

add_action( 'admin_print_styles-upload.php', 'sk_filesize_column_filesize' );




/**
 * Adjust File Size column on Media Library page in WP admin
 
function sk_filesize_column_filesize() {
    echo
    '<style>
        .fixed .column-filesize {
            width: 10%;
        }
    </style>';
}
*/

Retro-thanks for giving me the code over the years and future-thanks for helping me clear this out. :slight_smile:

Hello Peter,

Thanks for writing in.

Your function.php file actually looks clean. To improve it, you might want to indent the codes properly.

You can check for tools here: https://tinyurl.com/yd6jgra5

This is the block of code:

// Add Social Sharing and Link to Donations Page at bottom of all posts


add_action( 'x_before_the_content_end', 'x_print_social', 999);

function x_print_social() {

    if ( is_singular('post') ) {


        echo do_shortcode('[share title="Share the Magick!" facebook="true" google_plus="true" linkedin="true" pinterest="true" reddit="true"]');
        echo '<p style="text-align: center;"><a href="https://intothemythica.com/subscribe//">LIKE THIS ARTICLE? WANT TO HELP CHANGE THE WORLD? CLICK TO JOIN THE MYTHICA!</a>';


    }

}
// Add Author at bottom of all posts

add_action( 'x_before_the_content_end', 'x_post_category_slider', 998);
function x_post_category_slider () {

    if ( is_singular('post') ) {

        $category = get_the_category( get_the_ID() );

        $slider = "";

        if ( count( $category ) > 0 ) {

            switch ( $category[0]->term_id  ) {
                case 634: $slider = '[rev_slider alias="ftq-yeshualucis"]'; break;
                case 663: $slider = '[rev_slider alias="FTQ-peterfae"]'; break;
            }

            echo do_shortcode( $slider );
        }

        $author_id =  get_the_author_meta('ID');  
        echo do_shortcode('[author title="About the Author" author_id="'.$author_id.'"]');


    }

}

Hope this helps.

Thank you. I hear that. Yet I’m getting solid 502 errors and issues due to something I did with functions.php.

What would a basic download of functions.php look like, with no additional code? Where is the link here on X Theme?

Hi Peter,

A default functions.php file of the Pro child theme looks like this:

<?php

// =============================================================================
// FUNCTIONS.PHP
// -----------------------------------------------------------------------------
// Overwrite or add your own custom functions to Pro in this file.
// =============================================================================

// =============================================================================
// TABLE OF CONTENTS
// -----------------------------------------------------------------------------
//   01. Enqueue Parent Stylesheet
//   02. Additional Functions
// =============================================================================

// Enqueue Parent Stylesheet
// =============================================================================

add_filter( 'x_enqueue_parent_stylesheet', '__return_true' );



// Additional Functions
// =============================================================================

You can download it from here: https://theme.co/docs/child-themes#how-to-download-x-or-pro-child-themes

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.