I've added the Like Button plugin to my wordpress page and it adds a like/dislike button at the bottom of my wordpress post.
I'd like to change the position where the buttons are shown (to below my post's title), but I can't find where the function that draws the buttons is being called.
Any way I can change that by editing one of the php files?
Thank you.
You'll need to search plugin's source code for the the_content hook and remove it like this:
remove_filter('the_content', 'same_function_name', 10)
Be sure that the last number is the same as the add_filter function, otherwise it won't work.
Then you can create your own function like this:
<?php
function my_new_button_position( $title ) {
$button_html = call_plugin_function_that_was_in_the_content_hook();
$title .= $button_html;
return $title;
}
add_filter( 'the_title', 'new_button_position' );
?>
The call_plugin_function_that_was_in_the_content_hook() is the function that was called in the content hook.
Related
below is php code that another member posted which allows for a shortcode to be inserted in the short description of every woocommerce product page (code goes into the theme's function.php file). This has worked perfectly for me, but I have one more thing I need to achieve. I assume this is simple but I have primitive knowledge of php:
How do I make the inserted shortcode into a clickable link that links to a url of my choosing? Below is the code the is currently working and needs a hyperlink:
add_action( 'woocommerce_before_add_to_cart_form', 'enfold_customization_extra_product_content', 15 ); function enfold_customization_extra_product_content() {
echo do_shortcode("[wpqr-code]");}
Try:
add_action('woocommerce_before_add_to_cart_form','enfold_customization_extra_product_content', 15);
function enfold_customization_extra_product_content() {
echo ''. do_shortcode("[wpqr-code]") . '';
}
I have made a simple shortcode for my wordpress theme. I'm trying to align it on right-side above the corner of my page. Is it possible to insert shortcode function.php?
I want to place my Short-code in the top-bar (right side above the corner) so that it will work for each pages. Means if i click on any menu then the shortcode should have to work on that menu also.
Actually i'm new in web development. Please suggest me what shall i have to do so it will align where i want and should have work for each module.
You can use wordpress function for that. Please open the file on which you have to place shortcode. Like if you want to place it on header open header.php and add
<?php echo do_shortcode('[your_shortcode]'); ?>
where you want your shortcode content to appear
The best way is to find the top bar menu hook of your theme and then add this code (adapted for your needs) in your function.php child theme :
function my_shotcode_inside_top_bar ( $items, $args ) {
if (is_page() && $args->theme_location == 'secondary') {
$items .= '<li class="my-class">' . do_shortcode( "[my_shortcode]" ) . '</li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'my_shotcode_inside_top_bar', 10, 2 );
is_page displays the shortcode in pages only but you can choose another condition or no condition at all.
secondary is the hook and it depends on your theme. You can normally find it in your theme header.php file.
A menu location selector should be added - that way some themes support multiple menus, and some are called "top" or custom added.
The shortcode could then contain a call to whatever a menu position is:
EG: [myshortcode menu="secondary"]
Didn't have enough points to add this as a comment.
I'm trying to remove some hooks so that product categories don't show up on the homepage (of a Wordpress Storefront child theme).
I have the following code in my functions.php, which isn't working:
/**
* REMOVE SECTIONS ON HOMEPAGE
*/
add_action( 'init', 'remove_storefront_on_sale_products', 10 );
function remove_storefront_on_sale_products () {
?>
remove_action( 'homepage', 'storefront_on_sale_products', 60 );
<?php
}
Your code aint working because your line remove_action() is located outside of the php-tags.
Remove ?> and <?php in your above code and you should be fine.
First of all wordpress has not any action like "homepage" so you need to verify which action you are calling so if you want to remove function output only from homepage then you can do it by conditionally and secondly you didn't write proper php code, To achieve this you can write following in method.
if(!is_home()){
//Do stuff here if it is not homepage
}
OR
if(get_the_ID()!=101){ //101 your page id in which you don't want to show this
//Do stuff here if it is not homepage
}
I hope this may help you.
I am currently developing a theme for Wordpress 3.8.1. As my theme will not display any tags, so I want do disable them (only from the posts, not from custom post types). But how do I do this? I have tried this, but apparently, it does nothing:
register_taxonomy('post_tag', null);
To be clear: I do not just want to hide the tags in the template files, but I want to disable them completely, so in the backend, there is no menu item for tags under posts.
Is it even possible? I hope so. Thanks for your help!
Update
Additionally, I have tried the following, without any effect:
register_taxonomy('post_tag', array());
and
global $wp_taxonomies;
$taxonomy = 'post_tag';
if(taxonomy_exists($taxonomy))
unset($wp_taxonomies[$taxonomy]);
Both remove the tags box while editing a post, but there still is the link in the menu pointing to the list of tags!
As of WordPress 3.7, there is an unregister_taxonomy_for_object_type function available for just this sort of thing.
In your case:
// Remove tags support from posts
function myprefix_unregister_tags() {
unregister_taxonomy_for_object_type('post_tag', 'post');
}
add_action('init', 'myprefix_unregister_tags');
View the documentation for this function here.
Paste this code into your functions.php
add_action( 'admin_menu', 'myprefix_remove_meta_box');
function myprefix_remove_meta_box(){
remove_meta_box( 'tagsdiv-post_tag','post','normal' );
}
tags meta box has a class of tagsdiv-post_tag, so this will remove the tags meta box
OR
add_action('init', 'remove_tags');
function remove_tags(){
register_taxonomy('post_tag', array());
}
if you completely want to remove it
The best solution to disable rewrite rules for tags in posts for me was to use the post_tag_rewrite_rules filter hook.
add_filter( 'post_tag_rewrite_rules', '__return_empty_array' );
I wanted to add shortcode from the text editor of wordpress post.I have added following short code in the post of wordpress:
<img alt="" src="[template_url]/images/ic_sol_1a.png" />
Here [template_url] is the shortcode i wanted to use it was not working. when i see it in the post page it render the text not the short code response. Somewhere i saw a solutions like adding following line to functions.php of theme:
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');
But still after adding these lines i am unable to make shortcode work. What could be the possible reason?
my shortcode function is like this:
function my_template_url() {
return get_bloginfo('template_url');
}
add_shortcode("template_url", "my_template_url");
You will need to use the get_bloginfo() to return the value as in your example and make sure to use the_content() to print the value to the page. If you use one of the API methods such as get_the_content() then the do_shortcode filter is not run. If you want to apply it use the following:
function my_template_url() {
// This will echo the 'template_url'
return get_bloginfo('template_url');
}
add_shortcode("template_url", "my_template_url");
$shortcoded = apply_filters( 'the_content', get_the_content() );
You do not need the add_filter() lines.
After lots of headache and with the help of #doublesharp and #Nathan Dawson comments/answers we figured out Problem was inside single.php file of theme we were getting the content of post using get_the_content function. By changing it to the_content() function sortcodes start working. Please note that shortcode will not work in the visual editor of WordPress post on admin site but when you see the post actually in the browser by going to that post you can see it working.