Support » Plugins » Hacks » Change the core more-link style with class suffix

  • 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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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.. 😉

    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?

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change the core more-link style with class suffix’ is closed to new replies.