I want add Prettyphoto to my blog and I prepare filter:
add_filter( 'wp_get_attachment_link', 'sant_prettyadd');
function sant_prettyadd ($content) {
$content = preg_replace("/<a/","<a rel=\"prettyPhoto[slides]\"",$content,1);
return $content;
}
But where I should looking file function.php ?
When WordPress is integrated into Magento, the functions.php file is not used, which means that any code you add to it won't have any effect on the frontend of your blog.
The integration extension is Magento based and uses Magento templates to display your blog. You probably want to add the preg_replace function call to the post view template. This can be found at the following location:
app/design/frontend/base/default/template/wordpress/post/view.phtml
To make changes to this file, first copy it to your custom theme and edit it there. Look for the following line:
<?php echo $post->getPostContent() ?>
This is the code that retrieves the post content. You can use the preg_replace call here to achieve what you're trying to do.
Related
I am looking for a simple way to add shortcode to a custom widget(Not in custom template) which i have created using my function file in wordpress,so this shortcode can be used to show my custom stuffs..?Any help
WordPress widgets aren’t enabled to manage shortcodes.So there is a simple trick which can
be used here.
Open your function file and write the following code
add_filter(‘widget_text’, ‘do_shortcode’);
More can be found here
if you want to use the shortcode in widget script, you need to add a function like:
echo do_shortcode('[your_shortcode]');
I'm currently learning wordpress theme development and for better understanding I have downloaded couple of wordpress theme and seeing their code.
But a line of code I can't understand. here it is-->
<?php echo do_shortcode(sq_option( 'footer_text ' ' ')); ?>
maybe its for footer but how this works and how i can use this function when I will create my own.
do_shortcode is a function you have to use if you want to execute a shortcode inside a custom theme template page see more info on the function here: https://developer.wordpress.org/reference/functions/do_shortcode/
Generally do_shortcode(); is use to get data from shortcode or its attribute to your PHP code or to filter any shortcode returning data. Shortcode can be provided by any plugin.
Not sure about it but in your theme's code sq_option("footer_text"); could be a function which is filtering some text from footer.
The code could be as:
<?php echo do_shortcode( '[contact-form-7 id="91" title="quote"]' ); ?>
Reference Link
do_shortcode () is usefull function-> for excute shortcode in template file
i've written a plugin which shortcodes can easily be used in every post and page. As this plugin can be useful in a sidebar as well i want to make the text widget usable for my shortcodes.
When i googled this i found out that i can use the add_filter() function to ensure that, but this is only possible if i have access to the theme's functions.php. But as i am the creator of the plugin and not of the theme, this is not usable for me.
Does anybody know how i can make a shortcode which is introduced with a plugin usable in the widgets section?
Thanks!
Open your theme's function file.
Find a free spot after the opening php tag that isn't part of a function.
add this:
if (!is_admin())
{
add_filter('widget_text', 'do_shortcode', 11);
}
save the file and you should be all set.
Open your page in edit mode.
Select your page location and line where you want to add short code.
Add code here and update..
I want to modify/overwrite functions written in woocommerce-functions.php file but I don't want to modify woocommerce-functions.php file. That is I want to achieve this in plug-in or in my theme.
It is possible to override woocommerce functions, I did this recently and added all of my woocommerce extended functionality to my theme's functions.php file so that the woocommerce plugin files remained untouched and are safe to update.
This page gives an example of how you can remove their action and replace it with your own -
http://wordpress.org/support/topic/overriding-woocommerce_process_registration-in-child-theme-functionsphp
This page gives an example of extending upon their functions without removing their function, as well as using child themes -
http://uploadwp.com/customizing-the-woocommerce-checkout-page/
Hope this helps :)
WooCommerce provides a templating system. It is possible to override woocommerce functions. great way to customize WooCommerce without modifying core files, is to use hooks -
If you use a hook to add or manipulate code, you can add your custom code to your theme functions.php file.
Using action hooks -
To execute your own code, you hook in by using the action hook do_action(‘action_name’);.
See below for a great example on where to place your code:
add_action('action_name', 'your_function_name');
function your_function_name()
{
// Your code
}
Using filter hooks-
Filter hooks are called throughout are code using apply_filter(‘filter_name’, $variable);
To manipulate the passed variable, you can do something like the following:
add_filter('filter_name', 'your_function_name');
function your_function_name( $variable )
{
// Your code
return $variable;
}
Here you can get WooCommerce Action and Filter Hook - https://docs.woothemes.com/wc-apidocs/hook-docs.html
If you have a child theme, you can copy the relevant file to your theme and rewrite the copy. The copy will be used in preference to the WooCommerce version.
I was needed to add "Play" button for videos on mobile devices (by default this button is shown just on desktop).
I was needed to override the function in wp-content/themes/gon/framework/theme_functions.php:
function ts_template_single_product_video_button(){
if( wp_is_mobile() ){
return;
}
global $product;
$video_url = get_post_meta($product->id, 'ts_prod_video_url', true);
if( !empty($video_url) ){
$ajax_url = admin_url('admin-ajax.php', is_ssl()?'https':'http').'?ajax=true&action=load_product_video&product_id='.$product->id;
echo '<a class="ts-product-video-button" href="'.esc_url($ajax_url).'"></a>';
}
}
I found this instruction which states If you use a hook to add or manipulate code, you can add your custom code to your theme’s functions.php file.
I already had wp-content/themes/gon-child/functions.php, (ie the original gon theme had been copied to gon-child), so what I did was:
// Enable tour video on mobile devices
remove_action('ts_before_product_image', 'ts_template_single_product_video_button', 1);
add_action('ts_before_product_image', 'ts_template_single_product_video_button_w_mobile', 1);
function ts_template_single_product_video_button_w_mobile(){
global $product;
$video_url = get_post_meta($product->id, 'ts_prod_video_url', true);
if( !empty($video_url) ){
$ajax_url = admin_url('admin-ajax.php', is_ssl()?'https':'http').'?ajax=true&action=load_product_video&product_id='.$product->id;
echo '<a class="ts-product-video-button" href="'.esc_url($ajax_url).'"></a>';
}
}
?>
Is there any option to access a function inside function.php through a url?
Like joomla has this.
Any idea?
Use ajax functionality of wordpress:
HERE
You can use nopriv actions for that.
wp-admin/admin-ajax.php is the url for the ajax page of wordpress.
Or either you can make a template page which gives only content and create a shortcode
and add to a specific page.
functions.php is part of the core of your theme and is automatically included.
to access your function, simply use it in your theme file, as such:
<?php myfunc(); ?>