How to add new function

Posted in: Newspaper
Post count: 6

I need to have JavaScript inserted after the content in every post. I used to use a plugin called dpaBottomofPostPage but it now causes critical errors in WordPress.

It seems pretty simple but so far I can’t figure out where to put this code:

add_filter(‘the_content’, ‘add_my_content’);
function add_my_content($content) {
$my_custom_text = ‘Place the text you wish to insert below your post content here. Do not delete the single quote marks.’; //
if(is_single() && !is_home()) {
$content .= $my_custom_text;
}
return $content;
}

Adding it to the theme’s functions.php took down the site. Adding it to a loop_ page template did nothing.

Any ideas?

Post count: 23312

Hello Fasmon,

I have added your code in functions.php core file like this -> http://screencast.com/t/KnBaarELu and it seems to work as properly. Try again, clear all your caches and check the results.

Thanks.

Post count: 6

Here’s the script itself, plus some boilerplate:

<br><br><script type="text/javascript" src="http://imps.cardsynergy.com/imps_single_offer.php?&sid=35049&aid=a8f8c52a&cid=246411845"></script>

------------------------------------------------------------

<p>Editorial Disclaimer: The editorial content is not provided or commissioned by the credit card issuers. Opinions expressed here are author’s alone, not those of the credit card issuers, and have not been reviewed, approved or otherwise endorsed by the credit card issuers.</p>

<p>If you liked this post, <a href="http://feedburner.google.com/fb/a/mailverify?uri=milevalue&loc=en_US">sign up to receive one free daily email</a> every morning with all of the day’s posts! You can also follow MileValue on <a href="http://twitter.com/milevalue">Twitter</a> and <a href="http://www.facebook.com/milevalue">Facebook</a>.</p>

Perhaps there’s something wrong with the script?

Post count: 23312

Hello Fasmon,

Unfortunately, I am a bit confused with your latest reply, sorry! I have checked your first script and it seems to work as properly but with the second one, I do not understand, because it is totally different than the first one. Your first above script just add a content after each post, using the $my_custom_text variable. If you want to add something else in this script and if you are not aware of the steps which are needed to take in this regard, please consider hiring a freelancer/developer to help you because we cannot provide custom work at the moment, sorry!

Thanks for your understanding!

Post count: 6

Sorry, I was unclear. The second script goes here, inside the quotation marks in the first post. I hope that makes sense?

$my_custom_text = ‘Place the text you wish to insert below your post content here. Do not delete the single quote marks.’; //

Post count: 23312

Hello Fasmon,

I have implemented the following code to my functions.php core file and seems to work as expected. Try the code below and check the result -> http://screencast.com/t/Eys86WVAQ

add_filter('the_content', 'add_my_content');
function add_my_content($content) {
    $my_custom_text = '<br><br><script type="text/javascript" src="http://imps.cardsynergy.com/imps_single_offer.php?&sid=35049&aid=a8f8c52a&cid=246411845"></script>

------------------------------------------------------------

<p>Editorial Disclaimer: The editorial content is not provided or commissioned by the credit card issuers. Opinions expressed here are author’s alone, not those of the credit card issuers, and have not been reviewed, approved or otherwise endorsed by the credit card issuers.</p>

<p>If you liked this post, <a href="http://feedburner.google.com/fb/a/mailverify?uri=milevalue&loc=en_US">sign up to receive one free daily email</a> every morning with all of the day’s posts! You can also follow MileValue on <a href="http://twitter.com/milevalue">Twitter</a> and <a href="http://www.facebook.com/milevalue">Facebook</a>.</p>'; //
if(is_single() && !is_home()) {
    $content .= $my_custom_text;
}
return $content;
}

Hope this helps!

Thanks.

Post count: 6

Thanks for your work on this, but the JavaScript still doesn’t render, although the boilerplate does. The script works on the staging site, but not on the live site.

Could it have something to do with Flywheel’s server-side cache? Or the Let’s Encrypt SSL? Baffled.

  • This reply was modified 9 years by Fasmon.
Post count: 6535

Hi

You have a resource called from http and if your site runs over https the browser may block it. Basically if you’re using ssl all resources must be loaded trough https. It also could be an issue generated by server side cache so you can try to contact your host provider and ask for more details in this regard and also if can be turned off.

Thanks!

Viewing 8 posts - 1 through 8 (of 8 total)
The forum ‘Newspaper’ is closed to new topics and replies.