Last active
November 6, 2017 06:34
-
-
Save zeshanshani/d98cc70e61bdded3b3138fda2e437e3b to your computer and use it in GitHub Desktop.
Add Link to Widget Title using ACF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // This like is just for code highlighting purpose, don't copy it... | |
/** | |
* Insert link Inside Widget Title | |
* | |
* Author: Zeshan Ahmed | |
* Author URI: https://zeshanahmed.com/ | |
*/ | |
add_filter( 'dynamic_sidebar_params', 'update_dynamic_sidebar_params' ); | |
function update_dynamic_sidebar_params( $params ) { | |
// get widget vars | |
$widget_name = $params[0]['widget_name']; | |
$widget_id = $params[0]['widget_id']; | |
// bail early if ACF isn't activated. | |
if ( ! function_exists( 'get_field' ) ) { | |
return $params; | |
} | |
// add link to widget title. | |
$widget_link = get_field( '_widget_title_link', 'widget_' . $widget_id ); | |
if ( $widget_link ) { | |
$params[0]['before_title'] = $params[0]['before_title'] . '<a href="' . $widget_link . '">'; | |
$params[0]['after_title'] = '</a>' . $params[0]['after_title']; | |
} | |
// return | |
return $params; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment