change URL for wordpress wp_get_archives function - php

I'm using the wp_get_archives function in Wordpress.
<?php $args = array(
'type' => 'monthly',
'limit' => '',
'format' => 'html',
'before' => '',
'after' => '',
'show_post_count' => false,
'echo' => 1,
'order' => 'DESC'
); ?>
<?php wp_get_archives( $args ); ?>
But I want to be able to change the URL - rather than it going to my Wordpress installation directory, how can I change it to my own custom URL?
PS: I found on the general-template.php file starting at line 937 is where this function starts.

I saw that, inside the function wp_get_archives, the links are built with the function get_archives_link(). There, we find the filter hook get_archives_link that returns each HTML link for the archives.
So, we can manipulate each of this strings and replace stuff:
add_filter( 'get_archives_link', function( $html )
{
if( is_admin() ) // Just in case, don't run on admin side
return $html;
// $html is '<li><a href='http://example.com/hello-world'>Hello world!</a></li>'
$html = str_replace( 'href="http://example.com', 'href="http://example.org', $html );
return $html;
});

brasofilo's solution worked for me, with some minor adjustments.
before:
$html = str_replace( 'href="http://example.com', 'href="http://example.org', $html );
after:
$html = str_replace( 'http://example.com', 'http://example.com/the_events', $html );

Related

do_shortcode is not working on my index.php

I register a shortcode on my functions.php
function offer_intro_shortcode ($atts, $content=null) {
$offer = shortcode_atts( array (
'title' => '',
'text' => '',
), $atts );
extract ($offer);
return '<div class="center gap">
<h3>'.$title.'</h3>
<p class="lead">'.$text.'</p>
</div>';
}
add_shortcode ('offer', 'offer_intro_shortcode');
Then i write on wordpress post:
[offer title='What We Offer' text='Look at some of the recent projects we have completed for our valuble clients']
Then i query for this shortcode on my index.php like do_shortcode('[offer]')
But it is not working
try this.
echo do_shortcode("[offer title='What We Offer' text='Look at some of the recent projects we have completed for our valuble clients']");
check this is working or not.
After $atts add another parameter i.e shortcode so it would become.
$offer = shortcode_atts( array (
'title' => '',
'text' => '',
), $atts,'offer' );

Prepend hashtags in wordpress wp_tag_cloud

How can I prepend a "#" to the wp_tag_cloud?
This is my code so far
$args = array(
'order' => 'count',
);
wp_tag_cloud( $args );
A seperator does not work since this will not affect the first tag.
Thank you!
I can see a couple of options here. Based on your code, it looks like you're using the default 'format' => 'flat' argument. If you want to use this, you should be able to prepend hashtags to each tag using CSS. Something like the following:
a[class^="tag-link-"]::before {
content: '#';
}
Alternatively, you can use the 'format' => 'array' argument to return an array of tags, and then loop through them and echo them however you want. In PHP, this would look something like:
$args = array(
'order' => 'count',
'format' => 'array',
);
$tags = wp_tag_cloud( $args );
foreach ( $tags as $tag ) {
echo '#' . $tag . ' ';
}
Of course, there are even more elegant ways to use PHP to actually wrap the # in the same link tag.

WordPress Shortcode - Very puzzling issue?

I am trying to create a 'Pie Chart' shortcode to use in WP. All works fine apart from the percentage number. If it is entered into the array it works fine, but if I remove that number (ie; 100 - as seen in the code below), any number that is entered on the front-end by the user returns empty?? Quite puzzling?
function piechart_inner_shortcode( $atts ) {
extract( shortcode_atts( array(
'data_percentage' => '100',
'title' => 'Title',
), $atts ) );
$output = '<div class="chart"><div class="percentage" data-percent="'. $data_percentage .'"><span>'.$data_percentage.'%</span></div><div class="label"><strong>'.$title.'</strong></div></div>';
return $output;
}
add_shortcode( 'piechart_inner', 'piechart_inner_shortcode' );
And this is the shortcode that needs to be entered on the front-end -
[piechart_inner data-percent="45" title="WordPress"][/piechart_inner]
Which outputs nothing for the data-percent, whatever value is entered?
Many thanks
You are using the wrong variable. You are giving data-percent when you have variable data_percentage
Your shortcode should look like this:
[piechart_inner data_percentage="45" title="WordPress"][/piechart_inner]
Or change the function to following:
function piechart_inner_shortcode( $atts ) {
extract( shortcode_atts( array(
'data-percent' => '100',
'title' => 'Title',
), $atts ) );
$output = '<div class="chart"><div class="percentage" data-percent="'. $data-percent .'"><span>'.$data-percent.'%</span></div><div class="label"><strong>'.$title.'</strong></div></div>';
return $output;
}
add_shortcode( 'piechart_inner', 'piechart_inner_shortcode' );

Remove Specific Buttons from WP Editor TinyMCE

I am trying to figure out how to remove specific buttons from the TinyMCE editor. I have researched the arguments in the codex but for TinyMCE is just says array and not sure if I can include some paramters in my arguments of which buttons to show/hide?
I am using the editor in a gravity form and my code is as follows so far
add_action( 'gform_field_input', 'gforms_wp_editor', 10, 5 );
function gforms_wp_editor( $input, $field, $value, $lead_id, $form_id ) {
if( $field["cssClass"] == 'richtext' ) {
ob_start();
wp_editor( $value, "input_{$form_id}_{$field['id']}",
array(
'media_buttons' => false,
'quicktags' => false,
'textarea_name' => "input_{$field['id']}"
) );
$input = ob_get_clean();
}
return $input;
}
I have removed the HTML tab using the quicktags to false, so hoping I can do something similar to strip out buttons from the editor.
buttons shown right now with the code above are as follows
Note: 'teeny' editor is now what I need, just in case someone suggests
Thanks
The tinymce parameter allows you to pass configuration options directly to TinyMCE - see the docs for theme_advanced_buttons and theme_advanced_disable, and the button reference.
To show only the bold, italic and underline buttons:
wp_editor($value, "input...", array(
'tinymce' => array(
'theme_advanced_buttons1' => 'bold,italic,underline',
'theme_advanced_buttons2' => '',
'theme_advanced_buttons3' => ''
)
));
Or, to show everything except the bold, italic and underline buttons:
wp_editor($value, "input...", array(
'tinymce' => array(
'theme_advanced_disable' => 'bold,italic,underline'
)
));
As requested, your code modified:
add_action( 'gform_field_input', 'gforms_wp_editor', 10, 5 );
function gforms_wp_editor( $input, $field, $value, $lead_id, $form_id ) {
if( $field["cssClass"] == 'richtext' ) {
ob_start();
wp_editor( $value, "input_{$form_id}_{$field['id']}",
array(
'media_buttons' => false,
'quicktags' => false,
'textarea_name' => "input_{$field['id']}",
'tinymce' => array(
'theme_advanced_disable' => 'bold,italic,underline'
)
)
);
$input = ob_get_clean();
}
return $input;
}

inclue link list category as css class

I'd like to render some extra css classes in my wordpress links list, specifically id like to render the link category as a css class, so for example:
link : http://www.foobar.com/
gategories : friends, colleagues
name : Foo Bar
Currentyly renders as:
Foo Bar
But I want it to render as:
Foo Bar
I know that you use the following function to build the links list but i cant work out how to modify it to do what I need:
function wp_list_bookmarks($args = '') {
$defaults = array(
'orderby' => 'name', 'order' => 'ASC',
'limit' => -1, 'category' => '', 'exclude_category' => '',
'category_name' => '', 'hide_invisible' => 1,
'show_updated' => 0, 'echo' => 1,
'categorize' => 1, 'title_li' => __('Bookmarks'),
'title_before' => '<h2>', 'title_after' => '</h2>',
'category_orderby' => 'name', 'category_order' => 'ASC',
'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',
'category_after' => '</li>'
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
$output = '';
if(1) {
//output one single list using title_li for the title
$bookmarks = get_bookmarks($r);
if ( !empty($bookmarks) ) {
if ( !empty( $title_li ) ){
$output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before);
$output .= "$title_before$title_li$title_after\n\t<ul class=\"xoxo blogroll $category\">\n";
$output .= _walk_bookmarks($bookmarks, $r);
$output .= "\n\t</ul>\n$category_after\n";
} else {
$output .= _walk_bookmarks($bookmarks, $r);
}
}
}
$output = apply_filters( 'wp_list_bookmarks', $output );
if ( !$echo )
return $output;
echo $output;
}
?>
Thanks!
Firstly, you should never modify the Wordpress Core functions. In the case of Bookmarks, however, I don't really blame you for wanting to. They're kind of a pain.
I would just build it from scratch using get_bookmarks(). Here's a working example:
foreach(get_bookmarks() as $bm)
{
$terms = get_the_terms($bm->link_id, 'link_category');
$classes = array('wp_link');
if($terms)
foreach($terms as $term)
$classes[] = $term->slug;
echo '<a class="'.implode(' ', $classes).'" href="'.$bm->link_url.'"'.($bm->link_target ? 'target="'.$bm->link_target.'"' : '').'>'.$bm->link_name.'</a><br/>';
}
Just place this wherever it is in your template that you want to generate your bookmarks. Or you can wrap it up in a custom function call, and call that function from your template.

Categories