Tumblr: How to hide Disqus comments on Pages? - css

As far as I am aware in Tumblr there is no {block:Pages} block, so anything we add to normal posts is added to pages as well, things like sharing and worst of all, comment systems.
Does anyone know of a hack, or any way to remove/hide elements from pages? It's difficult because pages are using the {block:Permalink} {block:Text} blocks, so I'm pretty stumped.
I recently just discovered how to modify CSS with post tags using just HTML over here: Tumblr: How to control CSS with post tagging (UPDATE: Working Method without JQuery!)
I thought maybe we can use this, the idea would be something like this:
{block:Text}
<div class="post {block:HasTags}pagefix {block:Tags}{Tag}{/...}">
...
{/block:Text}
The way it works is by default we hide any element we don't want to be shown on pages (example: Disqus), adding the class .pagefix between {block:HasTags} in the div wrapper we can tell it to show elements on posts with tags, that way elements will only be shown on posts and not pages, because pages don't have tags.
Two problems with this, 1) all posts MUST be tagged in order to show any hidden items and 2) the Disqus comment script would have to be inserted into every post type, rather than just once before the {/block:Posts} end block.
I may be just placing Disqus in the wrong place, or some other error, let me know what you think, I can't find anything at all about this on the net anywhere. It's so dumb not to have a unique page block...

Simply wrap your Disqus code in the date block.
{block:Date}
<!-- Disqus code -->
{/block:Date}
Since only posts have dates, the Disqus code will never get rendered on a page. This also solves the problem above where having only one post breaks the method.

The trick is to wrap your Disqus code in {block:PermalinkPagination} tags as follows:
{block:PermalinkPagination}
...disqus code...
{/block:PermalinkPagination}
Your question is a partial duplication of this one on webapps.stackexhange.com, a full explanation can be found here.

There is also a problem with disqus code whereby if you want to have the comment count show on the front page but not a comment box (but have the comment box and comments as well as the comment count show on the Permalink page) you must do the following:
Append #disqus_thread to the direct page link e.g.
Do NOT wrap the disqus code in {block:PermalinkPagination}{/block:PermalinkPagination} as this will hide comments from the front page. Remove that block if it exists, and wrap the top part of the disqus script only in {block:Permalinkpage}{/block:Permalinkpage} - exact disqus code for Tumblr reproduced below;
{block:IfDisqusShortname}
{block:Permalinkpage}
<script type="text/javascript">var disqus_url = "{Permalink}"; var disqus_title ="{block:PostTitle}{PostTitle}{/block:PostTitle}";</script>
<div id="disqus_thread"></div>
<script type="text/javascript">
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://{text:Disqus Shortname}.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the comments powered by Disqus.</noscript>
{/block:Permalinkpage}
<!--{Title}'s comments powered by <span class="logo-disqus">Disqus</span>-->
<script type="text/javascript">
var disqus_shortname = '{text:Disqus Shortname}';
(function () {
var s = document.createElement('script'); s.async = true;
s.src = 'http://{text:Disqus Shortname}.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>
{/block:IfDisqusShortname}
</div>

Related

Custom Image on Google Tag Manager (AMP)

I need to add custom scripts to my AMP GTM container.
We have one for a facebook event. For custom image URL we are using https://www.facebook.com/tr?id=[MY_ID]=PageView&noscript=1
I need to do something similar for Pardot.
<script type="text/javascript">
piAId = '123456';
piCId = '123';
piHostname = 'pi.pardot.com';
(function() {
function async_load(){
var s = document.createElement('script'); s.type = 'text/javascript';
s.src = 'https://pi.pardot.com/pd.js';
var c = document.getElementsByTagName('script')[0]; c.parentNode.insertBefore(s, c);
}
if(window.attachEvent) { window.attachEvent('onload', async_load); }
else { window.addEventListener('load', async_load, false); }
})();
</script>
We have other types of tracking that I'd like to have a custom image for so we can do everything in our GTM container.
Is this possible to do the same way I did facebook? Is there a standard way of doing this? Adding query args?
Any help / guidance is appreciated
There is no custom HTML tag in an AMP container, since the use of AMP is restricted in AMP pages in the first place.
AMP pages can’t include any author-written JavaScript. Instead of
using JavaScript, interactive page features are handled in custom AMP
elements.
(Source)
I think you knew that, even though you asked for custom script.
For the real question if you can convert the Pardot script to a custom image tag I do not see any straightforward solution. The linked script reads cookies and HTML parameters and loads additional javascript. Custom images cannot do that (and the AMP container does not have a cookie variable, so you cannot get at the values through GTM).
This really looks like a case for Pardot tech support to see if they have an AMP compatible version of their tag.

Prevent TinyMCE wrapping text in p tags on Wordpress

Sorry for my english, I'm not a native speaker.
I've been trying to solve this problem for hours with no luck so far.
The question looks like a duplicate of questions asked previously here on Stack Overflow, but none of the solutions found here worked for me.
TinyMCE wraps anything you put in there inside p tags. I need to change the forced_root_block setting of tinymce to prevent this but I have no idea on how to achieve that on Wordpress.
I tried putting the code found here in my functions.php, but It did not work. Also, the problem doesn't revolve around "wpautop". It's just a TinyMCE problem: it puts the p tags as a default behaviour because it needs a root block. In my case I don't need a root block, because the editor's content is just a plain text whose root block is in my template's code. The added p tags simply break my layout, putting unnecessary html elements.
I tried using the TinyMCE advaced plugin, which has this option:
Stop removing the <p> and <br /> tags when saving and show them in the Text editor
but when this is not checked has the effect of "stripping" all the p tags, even the ones I intentionally use in the editor.
All I want to achieve is to prevent the editor from adding unwanted p tags and, at the same time, keep the p tags I intentionally use.
Is there a way to edit the forced_root_block setting of TinyMCE on Wordpress?
EDIT: After too many hours I was messing up between two different Wordpress installations I was working on at the same time. The solution of the linked post worked for me, but I was checking the results on the other site. By putting this:
function change_mce_options($init){
$init["forced_root_block"] = false;
$init["force_br_newlines"] = true;
$init["force_p_newlines"] = false;
$init["convert_newlines_to_brs"] = true;
return $init;
}
add_filter('tiny_mce_before_init','change_mce_options');
in my functions.php, TinyMCE stopped putting anything inside p tags. The Stop removing the <p> and <br /> tags when saving and show them in the Text editor of TinyMCE Advaced needs to be checked.
You could try to set
forced_root_blocks: false,
You can have a look at this wordpress plugin to change this setting.
Here is another possibility: http://wpengineer.com/1963/customize-wordpress-wysiwyg-editor/
Add this filter to functions.php:
function my_mce_options( $init ) {
$init['wpautop'] = false;
$init['indent'] = true;
$init['tadv_noautop'] = true;
return $init;
}
add_filter( 'tiny_mce_before_init', 'my_mce_options' );

Change wordpress menu href

I wanna change the href of a specific menu item on all pages. Is this possible? Where should I put the code?
I also added this javascript to the end of a specific page:
<script type="text/javascript">
document.getElementById("menu-item-100").href="xyz.php";
</script>
It didn't work even though when I viewed the page source it showed that the script was placed after the original href of the menu.
I don't wanna use custom links.
Try putting this in your footer.php
<script>
jQuery(document).ready(function($) {
$("#menu-item-100").attr("href", new_href);
});
</script>
Wordpress a lot of the times needs to have jQuery(document).ready(function($) for no-conflict reasons.
Try it, may be helpful to you:
$("#menu-item-100").attr("href", new_href);
Apparently the element with the ID of menu-item-100 had an a tag inside of it; so I had to retarget the whole thing.
This fixed the whole thing.
document.getElementById('menu-item-100').getElementsByTagName('a')[0].href="THE LINK";
Thanks to #NooBskie I put it inside the footer.php and it affected all the pages.

How do i disable submenu links in wordpress?

As soon as you create a menu item for a page there is a link that it automatically populated with it. How do i stop wordpress from making these links? I'm capable of making them myself and don't always want them to link to thier specific page.
I figured it out using and dropping it in my header.php
<script type="text/javascript">
jQuery(function($) {
$("li.menu-item-627,li.menu-item-14,li.menu-item-20,li.menu-item-28").children("a").attr('href', "javascript:void(0)");
});
</script>
You have to use firebug or chrome "inspect element" to find out what your menu items are and then just replace the numbers in the code accordingly.
also if you don't want them to show up at all add the following code
<script type="text/javascript">jQuery(function($) { $("li.menu-item-627").contents().hide();});</script>
those two together will hide the disabled menu link
you can then add your own links in the "navigation label" of the page menu field!
good luck and let me know if you have any questions, i will do my best to help!

Drupal 6: Theme Developer gives too common candidate name, nothing specific

I'm working on a restaurant directory site. I have restaurant details page that I need to implement gmap, slideshow, etc. So I need a specific page.tpl and Theme Developer gives the info as below
alt text http://img.skitch.com/20100708-b9af98fb8mpckai5wfpmktxwgf.jpg
but site's about us, contact us, faq, etc pages has same candidate name as page-node.tpl.php . So I can't use that :/
Why isnt there anything like page-restaurant.tpl.php
how can I solve this? Appreciate helps so much! thanks a lot!
[SORTED]
<script type="text/javascript">
window.onload = function() {
load();
}
window.onunload = function() {
GUnload();
}
</script>'
If you are just wanting to add Javascript code, you can use the CSS class provided with most themes. For example, Zen will give you
<body class="not-front logged-in node-type-restaurant two-sidebars page-restaurant">...</body>
which you can detect with jQuery as
$(document).ready() { $('.page-restaurant').Myfunction(); }
Regarding slideshow, I've had good luck with Views Slideshow, which provides a block you can just place in a region on your page.
We had a similar question yesterday.
The logic of drupal is that the page should be for the common elements of a page accross all types of page and content types. Page is the top level template, if you are trying to change that per content type you may not have seperated your theme correctly. You have node theming for differentiating between the different types of node. The format is node-[NODE TYPE].tpl.php
Have you created a content type "restaurant"? If you do this, you may find modules like gmap will help you out.
Add the following function to your template.php file. Replace "themename" with the actual name of your theme. This assumes you've created a separate content type for "restaurant" - I gather you have from the previous answers and comments. You'll get an option to use page-restaurant.tpl.php once you upload the edited template.php file and refresh the theme registry.
function themename_preprocess(&$vars, $hook) {
switch ($hook){
case 'page':
// Add a content-type page template in second to last.
if ('node' == arg(0)) {
$node_template = array_pop($vars['template_files']);
$vars['template_files'][] = 'page-' . $vars['node']->type;
$vars['template_files'][] = $node_template;
}
break;
}
return $vars;
}

Resources