Jump to content
colintsui

Add javascript codes to the end of post metabar

Recommended Posts

colintsui

Hello I'd like to edit the theme file containing the post metabar to include some javascript, preferrably inside the loop.php (because need to use php to call permalink and post title for each post) but i couldn't find this file, would you please advice me which file to edit? I've already created a child theme for this purpose.

Thanks in advance

Share this post


Link to post
Share on other sites
Danny

Hi Colin,

This will most likely require the use of a hook. Therefore, can you provide the code you wish to add and we can point you in the right direction.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
colintsui

Hello Danny,

here is the code:


<span style="padding:0 0 0 6px;"><script type="text/javascript" charset="utf-8">

(function(){

  var _w = 72 , _h = 16;

  var param = {

    url:'<?php the_permalink(); ?>',

    type:'3',

    count:'1', /**是否显示分享数,1显示(可选)*/

    appkey:'', /**您申请的应用appkey,显示分享来源(可选)*/

    title:'<?php the_title(); ?>', /**分享的文字内容(可选,默认为所在页面的title)*/

    pic:'<?php if (has_post_thumbnail( $post->ID ) ): ?><?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?><?php echo $image[0]; ?><?php endif; ?>', /**分享图片的路径(可选)*/

    ralateUid:'1795478825', /**关联用户的UID,分享微博会@该用户(可选)*/

language:'zh_cn', /**设置语言,zh_cn|zh_tw(可选)*/

    rnd:new Date().valueOf()

  }

  var temp = [];

  for( var p in param ){

    temp.push(p + '=' + encodeURIComponent( param[p] || '' ) )

  }

  document.write('<iframe allowTransparency="true" frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?' + temp.join('&') + '" width="'+ _w+'" height="'+_h+'"></iframe>')

})()

</script></span>

Thanks!

Share this post


Link to post
Share on other sites
Simon

You'd be better to use a shortcode, add this to your childtheme functions.php:


function wieboshare() {
ob_start(); ?>
<span style="padding:0 0 0 6px;"><script type="text/javascript" charset="utf-8">
(function(){
var _w = 72 , _h = 16;
var param = {
url:'<?php the_permalink(); ?>',
type:'3',
count:'1', /**是否显示分享数,1显示(可选)*/
appkey:'', /**您申请的应用appkey,显示分享来源(可选)*/
title:'<?php the_title(); ?>', /**分享的文字内容(可选,默认为所在页面的title)*/
pic:'<?php if (has_post_thumbnail( $post->ID ) ): ?><?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?><?php echo $image[0]; ?><?php endif; ?>', /**分享图片的路径(可选)*/
ralateUid:'1795478825', /**关联用户的UID,分享微博会@该用户(可选)*/
language:'zh_cn', /**设置语言,zh_cn|zh_tw(可选)*/
rnd:new Date().valueOf()
}
var temp = [];
for( var p in param ){
temp.push(p + '=' + encodeURIComponent( param[p] || '' ) )
}
document.write('<iframe allowTransparency="true" frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?' + temp.join('&') + '" width="'+ _w+'" height="'+_h+'"></iframe>')
})()
</script></span>
<?php $code = ob_get_clean();
return $code;
}
add_shortcode( 'wieboshare', 'wieboshare' );
[/CODE]

now you can place [wieboshare] in the metabar.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Similar Content

    • Michael Kummer
      By Michael Kummer+
      Hi guys!
      I am using a plugin called Speed Booster Pack to speed up the load time of michaelkummer.com. One of the plugin settings, Minimize HTML and JavaScript causes an error that I only get with Pagelines. With other themes, such as WordPress' Twenty Seventeen, I do not get that error.
      I have reproduced the problem on my staging site and if you look at the JavaScript console, you will see the following error:
      SyntaxError: Unexpected end of script
      Any clue what PageLines may be doing differently to be contributing to this issue? I contacted the plugin developer and they, of course, pointed me to the theme developer
      Thanks
      Michael
    • flourishdesignstudio
      By flourishdesignstudio+
      Hello,
      We are working on a site and the customers are complaining that the site loads too slowly. They contacted their host who mentioned that the Java Script is all loading at the beginning. Is it possible to delay the load of the less important Java Script until after the initial load to speed up the site? The goal is to load the page faster by minimizing the initial javascript calls.
      Are there any preferred plugins that you would recommend or does this end up causing excessive problems with plugins, etc.?
      Thanks for the help!
    • Dan Haddock
      By Dan Haddock
      Hi Pagelines team and wider community,
      I am looking to develop a single post page for my blog. I have read over an old article on the subject, however the link provided on achieving this goal was giving me security warnings. Is there any way I can get round this?
      Secondly, I have had a root around the .zip file provided on my sites backup, however was unable to locate any file in there with the name of Single.php. Does this file exist in the Pagelines theme?
      By the way, this is the unsafe article: http://support.pagelines.me/docs/customization/create-a-custom-page-template/ (Click at your peril).
       
    • Queue-it
      By Queue-it+
      Hi,
      How can I remove the "next post" links below each post page? 
      https://queue-it.com/cdn-blog/
      Before we had a related post section, but I can't find it among any functions, widgets etc. 

    • chamois_blanc
      By chamois_blanc+
      I am trying to clone a container on a page. It throws the following javascript error:
      function l(b, c, e, f) { var g = m.a.f.get(b, p); if (!c) { if (g) throw Error("You cannot apply bindings multiple times to the same element."); m.a.f.set(b, p, !0) } I would appreciate guidance and a fix. Thank you
×