php - replace string in get_permalink() function? -


i'm struggling rewrite urls. bc facebook doesn't follow 301 redirects likes (ugh) i'm needing find way rewrite og:url parameter wordpress spits out http in there instead of https.

i'm trying following no avail:

<?php  $oldlink = get_permalink(get_the_id()); $newlink = str_replace('https', 'http', $oldlink); ?> <meta property="og:url" content="<?php echo $newlink ?>"/> 

any ideas why method might not work?

if you're using in header.php , page you're loading single post/page/custom post can use the_post(); before statement in order initiate loop.

<?php the_post(); ?> <meta property="og:url" content="<?php $oldlink = get_permalink(get_the_id()); $newlink=str_replace('https','http',$oldlink); echo $newlink; ?>" /> 

the thing get_the_id() function works within loop, out initiating it returns fault results causing get_permalink function return nothing useful.

but careful, if call the_post later again on same single page after first 1 can mess data output. sure call once per single page (if you're not creating custom loop of cource).


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -