WordPress.org

Ready to get started?Download WordPress

Forums

Change the core more-link style with class suffix (4 posts)

  1. PyroCode
    Member
    Posted 3 years ago #

    Ah...more learning time! Does anyone have a coding method to add php variable to the end of the "more-link" style in the WordPress core by adding it to the functions.php file? Basically letting a person choose from theme settings their choice of a Read More button which would add their choice to the end of the more-link. Example, you choose blue in theme settings, this will add to the existing class="more-link-blue" in the page.

    I'd rather do this direct with the "actual" more-link from the functions.php than to add a another style to the more link there.

    Is this possible? Thanks in Advanced!

  2. Mark / t31os
    Moderator
    Posted 3 years ago #

    Add as many classes as you need into the array... :)

    $var_declared_outside_function = 'something';
    
    add_filter( 'the_content_more_link', 'add_morelink_classes' );
    function add_morelink_classes( $more_link_html ) {
    	// Example - else this var has no scope inside the function
    	global $var_declared_outside_function;
    
    	$new_classes = array( 'newclass1', 'newclass2' );
    	$more_link_html = str_replace( 'class="more-link', 'class="' . implode( ' ', $new_classes ) . ' more-link', $more_link_html );
    
    	return $more_link_html;
    }

    If you're pulling classes from your own variable that's declared outside the function remember to globalise the var..

    global $your_var_with_data;

    Hope that helps.. ;)

  3. PyroCode
    Member
    Posted 3 years ago #

    Thanks Mark, I will give this a try (as I'm still a beginner in php and wordpress methods). For the global var... where would I be placing that line?

  4. Mark / t31os
    Moderator
    Posted 3 years ago #

    Added an example into the code i posted in my last response.. :)

Topic Closed

This topic has been closed to new replies.

About this Topic